[SIP-5] Build metrics in query_object in the client

- Unify the metric interface (absorb the current plain string metric for built-in metric keys into the format used by adhoc metric)
- Port the logic in adhocMetric on the client and process_metrics in the backend to the new typed Metrics class
- Omit hasCustomLabel and formFromData properties from the new metric interface as their value can be inferred from label and optionName
- Expose from the Metrics class both metrics and their labels as public methods to match the all_metrics and metric_labels fields in the backend code
- Provide defaut values for filters, metrics and groupby in the backend
This commit is contained in:
Christine Chambers
2018-11-21 19:12:08 -08:00
committed by Christine Chambers
parent 2731a010ca
commit c11e9c8b67
7 changed files with 233 additions and 17 deletions

View File

@@ -1,9 +1,11 @@
import FormData, { getGranularity } from './FormData';
import Metric, { Metrics } from './Metric';
// TODO: fill out the rest of the query object
export interface QueryObject {
granularity: string;
groupby?: string[];
metrics?: Metric[];
}
// Build the common segments of all query objects (e.g. the granularity field derived from
@@ -14,5 +16,6 @@ export interface QueryObject {
export default function buildQueryObject<T extends FormData>(formData: T): QueryObject {
return {
granularity: getGranularity(formData),
metrics: new Metrics(formData).getMetrics(),
};
}