warning is a full sentence mentioning cluster name

This seems like a more helpful log message for operators, especially those
with many clusters.

Signed-off-by: Jamie Klassen <jklassen@vmware.com>
This commit is contained in:
Jamie Klassen
2022-12-14 17:49:56 -05:00
parent b008ccee54
commit 7341131af5
2 changed files with 7 additions and 6 deletions
@@ -388,7 +388,7 @@ describe('KubernetesFetcher', () => {
],
});
expect(warn).toHaveBeenCalledWith(
'statusCode=401 for resource /api/v1/services body=[{"kind":"Status","apiVersion":"v1","code":401}]',
'Received 401 status when fetching "/api/v1/services" from cluster "cluster1"; body=[{"kind":"Status","apiVersion":"v1","code":401}]',
);
});
// they're in testErrorResponse
@@ -109,7 +109,7 @@ export class KubernetesClientBasedFetcher implements KubernetesFetcher {
resources: items,
}),
)
: this.handleUnsuccessfulResponse(r),
: this.handleUnsuccessfulResponse(params.clusterDetails.name, r),
),
);
@@ -147,22 +147,23 @@ export class KubernetesClientBasedFetcher implements KubernetesFetcher {
}),
);
} else if (podMetrics.ok) {
return this.handleUnsuccessfulResponse(podList);
return this.handleUnsuccessfulResponse(clusterDetails.name, podList);
}
return this.handleUnsuccessfulResponse(podMetrics);
return this.handleUnsuccessfulResponse(clusterDetails.name, podMetrics);
});
return Promise.all(fetchResults).then(fetchResultsToResponseWrapper);
}
private async handleUnsuccessfulResponse(
clusterName: string,
res: Response,
): Promise<KubernetesFetchError> {
const resourcePath = new URL(res.url).pathname;
this.logger.warn(
`statusCode=${
`Received ${
res.status
} for resource ${resourcePath} body=[${await res.text()}]`,
} status when fetching "${resourcePath}" from cluster "${clusterName}"; body=[${await res.text()}]`,
);
return {
errorType: statusCodeToErrorType(res.status),