Skip to content

Commit

Permalink
Fix #1008 Add validation for unknown metric types (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
robhudson authored Nov 4, 2020
1 parent 8e9a753 commit f8d7c14
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
([#980](https://github.com/mozilla/glam/pull/980))
- Add `scalar` to list of known metric types for desktop
([#1007](https://github.com/mozilla/glam/issues/1007))
- Add validation for unknown metric types
([#1008](https://github.com/mozilla/glam/issues/1008))

## [2020.10.3](https://github.com/mozilla/glam/compare/2020.10.2...2020.10.3) (2020-10-20)

Expand Down
11 changes: 9 additions & 2 deletions src/config/fenix.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { transformAPIResponse } from '../utils/transform-data';
import { extractBucketMetadata } from './shared';
import { getProbeData } from '../state/api';
import { validate, noResponse } from '../utils/data-validation';
import {
validate,
noResponse,
noUnknownMetrics,
} from '../utils/data-validation';

export default {
label: 'Fenix',
Expand Down Expand Up @@ -92,7 +96,10 @@ export default {
const { aggregationLevel } = appStore.getState().productDimensions;

const metricType = payload.response[0].metric_type;
validate(payload, (p) => noResponse(p));
validate(payload, (p) => {
noResponse(p);
noUnknownMetrics(p, Object.keys(this.probeView));
});
const viewType =
this.probeView[metricType] === 'categorical'
? 'proportion'
Expand Down
11 changes: 9 additions & 2 deletions src/config/firefox-desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { extractBucketMetadata } from './shared';
import { transformAPIResponse } from '../utils/transform-data';
import { isSelectedProcessValid } from '../utils/probe-utils';
import { getProbeData } from '../state/api';
import { validate, noResponse } from '../utils/data-validation';
import {
validate,
noResponse,
noUnknownMetrics,
} from '../utils/data-validation';

export default {
label: 'Firefox',
Expand Down Expand Up @@ -112,7 +116,10 @@ export default {
const { aggregationLevel } = appStore.getState().productDimensions;

const metricType = payload.response[0].metric_type;
validate(payload, (p) => noResponse(p));
validate(payload, (p) => {
noResponse(p);
noUnknownMetrics(p, Object.keys(this.probeView));
});
const viewType =
this.probeView[metricType] === 'categorical'
? 'proportion'
Expand Down
21 changes: 10 additions & 11 deletions src/utils/data-validation.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
export const noDuplicates = (payload, aggregationMethod = 'build_id') => {
// go through ever data
// look at data[...].metadata[aggregationMethod]. There should be no duplicates.
const allBuildIDs = payload.response.map((di) => di[aggregationMethod]);
const uniques = new Set(allBuildIDs);
if (allBuildIDs.length !== uniques.size) {
throw new Error(
`Duplicate ${
aggregationMethod === 'build_id' ? 'Build IDs' : 'Versions'
} found.`
);
export const noUnknownMetrics = (payload, probeViews = []) => {
// Ensure the probe metric type is in our list of `probeView`s.
const metricType = payload.response[0].metric_type;
if (!(metricType in probeViews)) {
const er = new Error('This metric type is currently unsupported.');
er.moreInformation =
`GLAM doesn't yet know how to aggregate "${metricType}" type metrics. ` +
'If you seeing aggregations of metrics of this type would be valuable for you, ' +
'or if you believe this is an error, please let us know.';
throw er;
}
};

Expand Down

0 comments on commit f8d7c14

Please sign in to comment.