Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

fix(INT-6744): add debug log if timeout error #576

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions src/steps/cloud-build/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cloudbuild_v1, google } from 'googleapis';
import { Client } from '../../google-cloud/client';
import { IntegrationStepContext } from '../../types';
import { CloudBuildLocations } from './constants';
import { CloudBuildEntitiesSpec, CloudBuildLocations } from './constants';

export class CloudBuildClient extends Client {
private client = google.cloudbuild({ version: 'v1' });
Expand Down Expand Up @@ -129,29 +129,41 @@ export class CloudBuildClient extends Client {

async iterateBuildBitbucketRepositories(
serverConfig: cloudbuild_v1.Schema$BitbucketServerConfig,
context: IntegrationStepContext,
callback: (
data: cloudbuild_v1.Schema$BitbucketServerRepository,
) => Promise<void>,
): Promise<void> {
const auth = await this.getAuthenticatedServiceClient();

await this.iterateApi(
(nextPageToken) => {
return this.client.projects.locations.bitbucketServerConfigs.repos.list(
{
auth,
pageToken: nextPageToken,
parent: serverConfig.name!,
},
try {
await this.iterateApi(
(nextPageToken) => {
return this.client.projects.locations.bitbucketServerConfigs.repos.list(
{
auth,
pageToken: nextPageToken,
parent: serverConfig.name!,
},
);
},
async (
data: cloudbuild_v1.Schema$ListBitbucketServerRepositoriesResponse,
) => {
for (const config of data.bitbucketServerRepositories || []) {
await callback(config);
}
},
);
} catch (err) {
if (err.code === 'ATTEMPT_TIMEOUT') {
context.logger.warn(
{ err },
`${CloudBuildEntitiesSpec.BUILD_BITBUCKET_SERVER_CONFIG._type} - Unable to fetch BitBucket repositories. This might be caused by expired credentials in the GCP console (Cloud Build).`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the variable is CloudBuildEntitiesSpec but actually comes from a constants file

);
},
async (
data: cloudbuild_v1.Schema$ListBitbucketServerRepositoriesResponse,
) => {
for (const config of data.bitbucketServerRepositories || []) {
await callback(config);
}
},
);
}

throw err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the following so that the step does not fail if ATTEMPT_TIMEOUT occurs.

Suggested change
}
throw err;
} else {
throw err;
}

}
}
}
2 changes: 1 addition & 1 deletion src/steps/cloud-build/steps/fetch-cloud-build-bb-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export const fetchCloudBuildBitbucketRepositoriesStep: GoogleCloudIntegrationSte

await client.iterateBuildBitbucketRepositories(
serverConfig!,
context,
async (repository) => {
const repositoryEntity =
createGoogleCloudBuildBitbucketRepoEntity(repository);
await jobState.addEntity(repositoryEntity);

await jobState.addRelationship(
createDirectRelationship({
_class: RelationshipClass.HAS,
Expand Down