Skip to content

Commit

Permalink
Merge branch 'bugfix/UTAPI-88-do-not-error-500-in-case-of-negative-me…
Browse files Browse the repository at this point in the history
…tric' into q/7.10
  • Loading branch information
bert-e committed Apr 10, 2023
2 parents 347cf3c + 0fc08f3 commit de73fe9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
9 changes: 4 additions & 5 deletions lib/ListMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,10 @@ class ListMetrics {
});

if (!areMetricsPositive) {
return cb(errors.InternalError.customizeDescription(
'Utapi is in a transient state for this time period as '
+ 'metrics are being collected. Please try again in a few '
+ 'minutes.',
));
log.info('negative metric value found', {
error: resource,
method: 'ListMetrics.getMetrics',
});
}
/**
* Batch result is of the format
Expand Down
18 changes: 2 additions & 16 deletions tests/unit/testMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getMetricResponse(schemaKey) {
return response;
}

function assertMetrics(schemaKey, metricName, props, isNegativeValue, done) {
function assertMetrics(schemaKey, metricName, props, done) {
const timestamp = new Date().setMinutes(0, 0, 0);
const timeRange = [timestamp, timestamp];
const expectedRes = getMetricResponse(schemaKey);
Expand All @@ -51,16 +51,6 @@ function assertMetrics(schemaKey, metricName, props, isNegativeValue, done) {
datastore,
logger,
(err, res) => {
if (isNegativeValue) {
assert(err.is.InternalError);
assert.strictEqual(
err.description,
'Utapi is in a transient state for this time period as '
+ 'metrics are being collected. Please try again in a few '
+ 'minutes.',
);
return done();
}
assert.strictEqual(err, null);
// overwrite operations metrics
if (expectedResProps.operations) {
Expand Down Expand Up @@ -98,13 +88,12 @@ function testOps(schemaKey, keyIndex, metricindex, isNegativeValue, done) {
if (keyIndex === 'storageUtilized' || keyIndex === 'numberOfObjects') {
key = generateStateKey(schemaObject, keyIndex);
val = isNegativeValue ? -1024 : 1024;
props[metricindex] = [val, val];
props[metricindex] = isNegativeValue ? [0, 0] : [val, val];
memBackend.zadd(key, timestamp, val, () =>
assertMetrics(
schemaKey,
schemaObject[schemaKey],
props,
isNegativeValue,
done,
));
} else if (keyIndex === 'incomingBytes' || keyIndex === 'outgoingBytes') {
Expand All @@ -116,7 +105,6 @@ function testOps(schemaKey, keyIndex, metricindex, isNegativeValue, done) {
schemaKey,
schemaObject[schemaKey],
props,
isNegativeValue,
done,
));
} else {
Expand All @@ -129,7 +117,6 @@ function testOps(schemaKey, keyIndex, metricindex, isNegativeValue, done) {
schemaKey,
schemaObject[schemaKey],
props,
isNegativeValue,
done,
));
}
Expand All @@ -145,7 +132,6 @@ Object.keys(metricLevels).forEach(schemaKey => {
schemaKey,
resourceNames[schemaKey],
null,
false,
done,
));

Expand Down

0 comments on commit de73fe9

Please sign in to comment.