in internal/healthchecks/api_check.go [131:173]
func runMonitoringCheck(logger logs.StructuredLogger, resource resourcedetector.Resource) error {
ctx := context.Background()
// New Monitoring Client
monClient, err := monitoring.NewMetricClient(ctx)
if err != nil {
return err
}
defer monClient.Close()
logger.Infof("monitoring client was created successfully")
if err := monitoringPing(ctx, *monClient, resource); err != nil {
logger.Infof(err.Error())
var apiErr *apierror.APIError
if errors.As(err, &apiErr) {
switch apiErr.Reason() {
case ServiceDisabled:
return MonApiDisabledErr
case AccessTokenScopeInsufficient:
return MonApiScopeErr
case IamPermissionDenied:
return MonApiPermissionErr
}
switch apiErr.GRPCStatus().Code() {
case codes.PermissionDenied:
return MonApiPermissionErr
case codes.Unauthenticated:
return MonApiUnauthenticatedErr
case codes.DeadlineExceeded:
return MonApiConnErr
case codes.Unavailable:
return MonApiConnErr
}
}
if errors.Is(err, context.DeadlineExceeded) {
return MonApiConnErr
}
return err
}
return nil
}