├── .gitignore ├── SweetSlackOps.png ├── navigationtiming.png ├── config ├── build │ └── prod │ │ └── tsconfig.json └── metricConfigs │ ├── index.ts │ ├── skillAssessmentMetrics.ts │ ├── teachMetrics.ts │ ├── workspaceMetrics.ts │ └── learnMetrics.ts ├── PrometheusUserMonitoringArchitecture.png ├── runDevServer.sh ├── Dockerfile ├── tslint.json ├── tsconfig.json ├── src ├── aggregators │ ├── distribution.ts │ ├── counter.ts │ ├── util.ts │ ├── __tests__ │ │ ├── counterTest.ts │ │ └── histogramTest.ts │ └── histogram.ts ├── makeMetricsAggregator.ts ├── server.ts └── __tests__ │ └── reportingTests.js ├── package.json ├── ecs.json ├── docker-compose.yaml ├── .circleci └── config.yml ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | lib/ -------------------------------------------------------------------------------- /SweetSlackOps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/prometheus-user-metrics/master/SweetSlackOps.png -------------------------------------------------------------------------------- /navigationtiming.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/prometheus-user-metrics/master/navigationtiming.png -------------------------------------------------------------------------------- /config/build/prod/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.json", 3 | "files": [ 4 | "../../../src/server.ts", 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /PrometheusUserMonitoringArchitecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacamp/prometheus-user-metrics/master/PrometheusUserMonitoringArchitecture.png -------------------------------------------------------------------------------- /runDevServer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | babel clientSrc/aggregatorClient.js --watch --out-file static/aggregatorClient.js & 4 | babel-watch serverSrc/server.js -------------------------------------------------------------------------------- /config/metricConfigs/index.ts: -------------------------------------------------------------------------------- 1 | import learnMetrics from './learnMetrics'; 2 | import skillAssessmentMetrics from './skillAssessmentMetrics'; 3 | import workspaceMetrics from './workspaceMetrics' 4 | import teachMetrics from './teachMetrics'; 5 | 6 | export default [...learnMetrics, ...skillAssessmentMetrics, ...workspaceMetrics, ...teachMetrics]; 7 | -------------------------------------------------------------------------------- /config/metricConfigs/skillAssessmentMetrics.ts: -------------------------------------------------------------------------------- 1 | import { MetricsConfig } from '../../src/aggregators/util'; 2 | 3 | const allowedMetrics: MetricsConfig = [ 4 | { 5 | name: 'sa_check_item', 6 | help: 'Time it takes to check a skill assessment item', 7 | type: 'histogram', 8 | labels: [ 9 | { 10 | name: 'appName', 11 | allowedValues: ['skill-assessment'], 12 | }, 13 | ], 14 | protocol: 'statsd', 15 | }, 16 | ]; 17 | 18 | export default allowedMetrics; 19 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8.9.3 2 | 3 | # aws env 4 | RUN curl -o /tmp/aws-env-linux-amd64 -L https://github.com/datacamp/aws-env/releases/download/v0.1-session-fix/aws-env-linux-amd64 && \ 5 | chmod +x /tmp/aws-env-linux-amd64 && \ 6 | mv /tmp/aws-env-linux-amd64 /bin/aws-env 7 | 8 | EXPOSE 9102 9 | 10 | RUN mkdir -p /home/node/app 11 | 12 | WORKDIR /home/node/app 13 | 14 | # Cache the installation of the npm packages 15 | COPY package-lock.json . 16 | COPY package.json . 17 | 18 | RUN npm install 19 | 20 | COPY . . 21 | 22 | RUN npm run build:prod 23 | 24 | USER node 25 | 26 | CMD ["bash", "-c", "eval $(aws-env) && npm start"] -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": [ 4 | "tslint:recommended", 5 | "tslint-config-airbnb", 6 | "tslint-config-prettier" 7 | ], 8 | "jsRules": {}, 9 | "rules": { 10 | "prettier": true, 11 | "object-shorthand-properties-first": false, 12 | "object-literal-sort-keys": false, 13 | "no-unused-variable": true, 14 | "no-console": false, 15 | "array-type": [ 16 | true, 17 | "array" 18 | ], 19 | "import-name": [ 20 | true, 21 | { 22 | "lodash": "_" 23 | } 24 | ] 25 | }, 26 | "rulesDirectory": [ 27 | "tslint-plugin-prettier" 28 | ] 29 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": [ 4 | "es5", 5 | "es6", 6 | "es2016", 7 | "dom", 8 | "dom.iterable", 9 | "esnext.asynciterable" 10 | ], 11 | "outDir": "./lib/", 12 | "sourceMap": true, 13 | "module": "commonjs", 14 | "moduleResolution": "node", 15 | "noEmitOnError": true, 16 | "target": "es5", 17 | "declaration": true, 18 | "removeComments": false, 19 | "noImplicitAny": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "noUnusedLocals": false, 22 | "pretty": true, 23 | "emitDecoratorMetadata": true, 24 | "experimentalDecorators": true 25 | } 26 | } -------------------------------------------------------------------------------- /config/metricConfigs/teachMetrics.ts: -------------------------------------------------------------------------------- 1 | import { MetricsConfig } from "../../src/aggregators/util"; 2 | 3 | const allowedMetrics: MetricsConfig = [ 4 | { 5 | name: "te_editor_page_load_time", 6 | help: "Measures the time to load the teach editor", 7 | type: "histogram", 8 | labels: [ 9 | { 10 | name: "appName", 11 | allowedValues: ["teach-editor"] 12 | }, 13 | { 14 | name: "contentType", 15 | allowedValues: [ 16 | "course", 17 | "assessment", 18 | "practice", 19 | ] 20 | }, 21 | { 22 | name: "underThreshold", 23 | allowedValues: ["true", "false"] 24 | } 25 | ], 26 | protocol: "statsd" 27 | }, 28 | ]; 29 | 30 | export default allowedMetrics; 31 | -------------------------------------------------------------------------------- /src/aggregators/distribution.ts: -------------------------------------------------------------------------------- 1 | import { StatsD } from "hot-shots"; 2 | 3 | import { 4 | IDistributionEvent, 5 | IDistributionMetric, 6 | } from "./util"; 7 | 8 | export interface IDistribution { 9 | record: (event: IDistributionEvent) => void; 10 | } 11 | 12 | export function makeDistribution( 13 | config: IDistributionMetric, 14 | statsdClient: StatsD 15 | ): IDistribution { 16 | const { protocol } = config; 17 | const name = `${protocol}.${config.name}`; 18 | const client = statsdClient; 19 | 20 | const recordStatsd = (event: IDistributionEvent) => { 21 | event.observations.forEach(observation => { 22 | client.distribution(name, observation, event.labels); 23 | }); 24 | }; 25 | 26 | return { 27 | record(event: IDistributionEvent) { 28 | if (protocol === "statsd") { 29 | recordStatsd(event); 30 | } else { 31 | console.log(`Unknown protocol: ${protocol}`); 32 | } 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metrics-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build:prod": "rm -rf lib && tsc -p config/build/prod", 9 | "start": "node lib/src/server.js" 10 | }, 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "body-parser": "^1.17.0", 15 | "express": "^4.15.0", 16 | "hot-shots": "6.3.0", 17 | "ts-node": "6.1.2", 18 | "typescript": "2.9.2", 19 | "unix-dgram": "2.0.4" 20 | }, 21 | "devDependencies": { 22 | "@types/express": "4.16.0", 23 | "@types/node": "10.3.4", 24 | "jest": "23.1.0", 25 | "jest-cli": "23.1.0", 26 | "prettier": "1.13.5", 27 | "tslint": "5.8.0", 28 | "tslint-config-airbnb": "5.4.2", 29 | "tslint-config-prettier": "1.6.0", 30 | "tslint-junit-formatter": "5.1.0", 31 | "tslint-plugin-prettier": "1.3.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ecs.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://assets.ops.datacamp.com/ecs.schema.json#", 3 | "services": [ 4 | { 5 | "cluster": "datacamp-services", 6 | "serviceName": "prometheus-aggregator", 7 | "containers": [ 8 | { 9 | "containerName": "prometheus-aggregator", 10 | "containerURI": "708371444347.dkr.ecr.us-east-1.amazonaws.com/prometheus-user-metrics:${CIRCLE_SHA1}", 11 | "containerPort": 3000, 12 | "memoryReservation": 256, 13 | "cpu": 700, 14 | "essential": true, 15 | "dockerLabels": { 16 | "com.datadoghq.ad.check_names": "[\"prometheus\"]", 17 | "com.datadoghq.ad.init_configs": "[{}]", 18 | "com.datadoghq.ad.instances": "[{\"prometheus_url\": \"http://%%host%%:9102/metrics\", \"namespace\": \"user_metrics\", \"metrics\": [\"*\"], \"send_histograms_buckets\": true}]", 19 | "com.datadoghq.ad.logs": "[{}]" 20 | }, 21 | "healthCheck": { 22 | "command": [ 23 | "CMD-SHELL", 24 | "curl -f http://localhost:3000/status || exit 1" 25 | ], 26 | "interval": 60, 27 | "startPeriod": 120 28 | } 29 | } 30 | ] 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | dev-server: 4 | build: 5 | context: . 6 | dockerfile: Dockerfile-dev 7 | command: 8 | - bash 9 | - runDevServer.sh 10 | ports: 11 | - 3000:3000 12 | - 9102:9102 13 | environment: 14 | PUM_CONFIG_PATH: /stage/metricConfigs 15 | volumes: 16 | - ./serverSrc:/stage/serverSrc 17 | - ./clientSrc:/stage/clientSrc 18 | - ./config/metricConfigs:/stage/metricConfigs 19 | 20 | # prod-server: 21 | # build: 22 | # context: . 23 | # dockerfile: Dockerfile 24 | # ports: 25 | # - 3000:3000 26 | # # Note: in production you should not expose port 9102. It is exposed here just to make it easier to manually verify GET :9102/metrics 27 | # - 9102:9102 28 | # environment: 29 | # PUM_CONFIG_PATH: /stage/metricConfigs 30 | # volumes: 31 | # - ./config/metricConfigs:/stage/metricConfigs 32 | 33 | demo-prom: 34 | image: prom/prometheus 35 | command: 36 | - -config.file=/prometheusConfig/prometheus.yml 37 | ports: 38 | - 9090:9090 39 | volumes: 40 | - ./demo/prometheusConfig:/prometheusConfig 41 | links: 42 | - dev-server:metrics-aggregator-dev-server 43 | 44 | demo-grafana: 45 | image: grafana/grafana 46 | ports: 47 | - 3001:3000 48 | volumes: 49 | - ./demo/grafanaConfig:/grafana-data 50 | links: 51 | - demo-prom 52 | environment: 53 | GF_AUTH_BASIC_ENABLED: "false" 54 | GF_AUTH_ANONYMOUS_ENABLED: "true" 55 | GF_AUTH_ANONYMOUS_ORG_ROLE: Admin 56 | GF_PATHS_DATA: /grafana-data 57 | 58 | # This server actually serves the demo code 59 | sample-web-server: 60 | image: nginx 61 | ports: 62 | - 8080:80 63 | volumes: 64 | - ./demo/sampleApp:/usr/share/nginx/html:ro -------------------------------------------------------------------------------- /src/makeMetricsAggregator.ts: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | import { 3 | flattenLabels, 4 | getLabelPermutations, 5 | ICounterEvent, 6 | IDistributionEvent, 7 | IHistogramEvent, 8 | MetricsConfig 9 | } from "./aggregators/util"; 10 | 11 | import { ICounter, makeCounter } from "./aggregators/counter"; 12 | import { IHistogram, makeHistogram } from "./aggregators/histogram"; 13 | import { IDistribution, makeDistribution } from "./aggregators/distribution"; 14 | 15 | import { StatsD } from "hot-shots"; 16 | 17 | export function makeAggregator(metricsConfig: MetricsConfig, client: StatsD) { 18 | const counters: { [metricName: string]: ICounter } = {}; 19 | const histograms: { [metricName: string]: IHistogram } = {}; 20 | const distributions: { [metricName: string]: IDistribution } = {}; 21 | 22 | metricsConfig.forEach(config => { 23 | if (config.type === "counter") { 24 | counters[config.name] = makeCounter(config, client); 25 | } else if (config.type === "histogram") { 26 | histograms[config.name] = makeHistogram(config, client); 27 | } else if (config.type === "distribution") { 28 | distributions[config.name] = makeDistribution(config, client); 29 | } 30 | }); 31 | 32 | return { 33 | consume(payload: ICounterEvent | IHistogramEvent | IDistributionEvent) { 34 | // TODO: maybe indicate success somehow? There are error codes returned that we ignore here. It would be nice to have a running metric of bad metrics that we could alarm on. 35 | if (payload.metricType === "counter") { 36 | if (counters[payload.metricName]) { 37 | counters[payload.metricName].record(payload); 38 | } 39 | } else if (payload.metricType === "histogram") { 40 | if (histograms[payload.metricName]) { 41 | histograms[payload.metricName].record(payload); 42 | } 43 | } else if (payload.metricType === 'distribution') { 44 | if (distributions[payload.metricName]) { 45 | distributions[payload.metricName].record(payload); 46 | } 47 | } 48 | }, 49 | 50 | reportMetrics() { 51 | const counterOutput = Object.keys(counters).map(key => 52 | counters[key].report() 53 | ); 54 | 55 | const histogramOutput = Object.keys(histograms).map(key => 56 | histograms[key].report() 57 | ); 58 | 59 | return [...counterOutput, ...histogramOutput].join("\n") + "\n"; 60 | } 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /src/aggregators/counter.ts: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { StatsD } from "hot-shots"; 4 | 5 | import { 6 | flattenLabels, 7 | getLabelPermutations, 8 | ICounterEvent, 9 | ICounterMetric 10 | } from "./util"; 11 | 12 | export interface ICounter { 13 | record: (event: ICounterEvent) => void; 14 | report: () => string; 15 | } 16 | 17 | export function makeCounter( 18 | config: ICounterMetric, 19 | statsdClient: StatsD 20 | ): ICounter { 21 | const { help, type, protocol } = config; 22 | const name = `${protocol}.${config.name}`; 23 | const client = statsdClient; 24 | 25 | const allowedLabelPermutations = getLabelPermutations(config.labels); 26 | const counterValues: { [key: string]: number } = {}; 27 | allowedLabelPermutations.forEach(permutation => { 28 | // initialize all allowed permutations to zero. 29 | counterValues[permutation] = 0; 30 | 31 | // later, all other permutations will be rejected, so this 32 | // secures the counters against misbehaving clients who would 33 | // send unknown labels or values and crash poor prometheus. 34 | }); 35 | 36 | const recordPrometheus = (event: ICounterEvent) => { 37 | const labelPermutationKey = flattenLabels(event.labels); 38 | if (typeof counterValues[labelPermutationKey] === "number") { 39 | counterValues[labelPermutationKey] += event.inc; 40 | } else { 41 | console.log(`Disallowed label permutation ${labelPermutationKey}`); 42 | } 43 | }; 44 | 45 | const recordStatsd = (event: ICounterEvent) => { 46 | console.log("increment", event); 47 | client.increment(name, event.inc, event.labels); 48 | }; 49 | 50 | return { 51 | record(event: ICounterEvent) { 52 | if (protocol === "statsd") { 53 | recordStatsd(event); 54 | } else if (protocol === "prometheus") { 55 | recordPrometheus(event); 56 | } else { 57 | console.log(`Unknown protocol: ${protocol}`); 58 | } 59 | }, 60 | 61 | report() { 62 | if (protocol === "prometheus") { 63 | const headerLines = [ 64 | `# HELP ${name} ${help}`, 65 | `# TYPE ${name} ${type}` 66 | ]; 67 | 68 | const bodyLines = Object.keys(counterValues).map( 69 | labelPermutationKey => { 70 | const value = counterValues[labelPermutationKey]; 71 | return `${name}{${labelPermutationKey}} ${value}`; 72 | } 73 | ); 74 | 75 | return headerLines.join("\n") + "\n" + bodyLines.join("\n"); 76 | } 77 | return ""; 78 | } 79 | }; 80 | } 81 | -------------------------------------------------------------------------------- /src/aggregators/util.ts: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export interface ILabel { 4 | name: string; 5 | allowedValues: string[]; 6 | } 7 | 8 | export interface IMetric { 9 | name: string; 10 | help: string; 11 | labels: ILabel[]; 12 | protocol: "statsd" | "prometheus"; 13 | } 14 | 15 | export interface ICounterMetric extends IMetric { 16 | type: "counter"; 17 | } 18 | 19 | export interface IHistogramMetricPrometheus extends IMetric { 20 | type: "histogram"; 21 | buckets: number[]; 22 | protocol: "prometheus"; 23 | } 24 | 25 | export interface IHistogramMetricStatsd extends IMetric { 26 | type: "histogram"; 27 | protocol: "statsd"; 28 | } 29 | 30 | export type IHistogramMetric = 31 | | IHistogramMetricPrometheus 32 | | IHistogramMetricStatsd; 33 | 34 | export interface IDistributionMetric extends IMetric { 35 | type: "distribution"; 36 | protocol: "statsd"; 37 | } 38 | 39 | export type MetricConfig = ICounterMetric | IHistogramMetric | IDistributionMetric; 40 | 41 | export type MetricsConfig = MetricConfig[]; 42 | 43 | export interface ICounterEvent { 44 | metricType: "counter"; 45 | metricName: string; 46 | labels: { [key: string]: string }; 47 | inc: number; 48 | } 49 | 50 | export interface IHistogramEvent { 51 | metricType: "histogram"; 52 | metricName: string; 53 | labels: { [key: string]: string }; 54 | observations: number[]; 55 | } 56 | 57 | export interface IDistributionEvent { 58 | metricType: "distribution"; 59 | metricName: string; 60 | labels: { [key: string]: string }; 61 | observations: number[]; 62 | } 63 | 64 | export function getLabelPermutations(labels: ILabel[]) { 65 | const results: string[] = []; 66 | 67 | function mutate( 68 | remainingLabels: ILabel[], 69 | accumulator: { [key: string]: string } 70 | ) { 71 | if (remainingLabels.length === 0) { 72 | const keys = Object.keys(accumulator).sort(); 73 | results.push(keys.map(key => `${key}="${accumulator[key]}"`).join(",")); 74 | } else { 75 | const head = remainingLabels[0]; 76 | const tail = remainingLabels.slice(1); 77 | 78 | head.allowedValues.forEach(allowedValue => { 79 | const newAccumulator = { 80 | ...accumulator, 81 | [head.name]: allowedValue 82 | }; 83 | 84 | mutate(tail, newAccumulator); 85 | }); 86 | } 87 | } 88 | 89 | mutate(labels, {}); 90 | return results; 91 | } 92 | 93 | export function flattenLabels(labelsObject: { [key: string]: string }) { 94 | const keys = Object.keys(labelsObject).sort(); 95 | const printed = keys.map(key => `${key}="${labelsObject[key]}"`); 96 | return printed.join(","); 97 | } 98 | -------------------------------------------------------------------------------- /src/server.ts: -------------------------------------------------------------------------------- 1 | import * as bodyParser from "body-parser"; 2 | import * as express from "express"; 3 | import { StatsD } from "hot-shots"; 4 | 5 | import metricConfigs from "../config/metricConfigs"; 6 | import { makeAggregator } from "./makeMetricsAggregator"; 7 | 8 | const statsdSock = process.env["DD_DOGSTATSD_SOCKET"]; 9 | let extraOptions = {}; 10 | 11 | if (statsdSock !== undefined) { 12 | extraOptions = { 13 | ...extraOptions, 14 | path: statsdSock, 15 | protocol: "uds", 16 | }; 17 | } 18 | 19 | const statsdClient = new StatsD({ 20 | ...extraOptions, 21 | useDefaultRoute: true, 22 | prefix: "user_metrics.", 23 | errorHandler: (error) => { 24 | console.log("Statsd socket error: ", error); 25 | }, 26 | }); 27 | 28 | const aggregator = makeAggregator(metricConfigs, statsdClient); 29 | 30 | // expose this publicServer to users so they can download the client & 31 | // post metrics to be aggregated. 32 | const publicServer = express(); 33 | publicServer.use((req, res, next) => { 34 | // Enable CORS. This is necessary for demos where end-user clients 35 | // connect directly to this server. In production, you should 36 | // hide this server behind your API gateway, which should 37 | // strip out these headers anyway. 38 | res.header("Access-Control-Allow-Origin", "*"); 39 | res.header( 40 | "Access-Control-Allow-Headers", 41 | "Origin, X-Requested-With, Content-Type, Accept" 42 | ); 43 | next(); 44 | }); 45 | 46 | publicServer.get("/status", (req, res) => { 47 | return res.status(200).send(); 48 | }); 49 | 50 | publicServer.use(bodyParser.json()); 51 | publicServer.post("/record", (req, res, next) => { 52 | const batch = req.body; 53 | batch.forEach(aggregator.consume); 54 | 55 | res.send("OK"); 56 | }); 57 | 58 | publicServer.use((err: any, req: any, res: any, next: any) => { 59 | console.error("Got error", err); 60 | next(err); 61 | }); 62 | 63 | publicServer.listen(3000, (err: any) => { 64 | if (err) { 65 | console.error("There was an error listening on 3000 for the public API"); 66 | console.error(err); 67 | process.exit(1); 68 | } else { 69 | console.log("Public API listening on 3000"); 70 | } 71 | }); 72 | 73 | // expose this server to prometheus so it can scrape /metrics 74 | const reportingServer = express(); 75 | reportingServer.get("/metrics", (req, res, next) => { 76 | res.set("Content-Type", "text/plain; version=0.0.4; charset=utf-8"); 77 | res.send(aggregator.reportMetrics()); 78 | }); 79 | 80 | reportingServer.listen(9102, (err: any) => { 81 | if (err) { 82 | console.error("There was an error listening on 9102"); 83 | console.error(err); 84 | process.exit(1); 85 | } else { 86 | console.log("Aggregator listening on 9102 "); 87 | } 88 | }); 89 | -------------------------------------------------------------------------------- /src/aggregators/__tests__/counterTest.ts: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | import { makeCounter } from "../counter"; 3 | import { MetricConfig } from "../util"; 4 | 5 | declare interface IExpectable { 6 | toBe: (t: T) => void; 7 | toBeNull: () => void; 8 | toBeTruthy: () => void; 9 | toBeFalsy: () => void; 10 | toContain: (t: any) => void; 11 | toEqual: (t: T) => void; 12 | not: IExpectable; 13 | } 14 | 15 | declare type DoneCb = () => void; 16 | 17 | declare function beforeAll(prepare: ((done: DoneCb) => void)): void; 18 | declare function describe(description: string, tests: (() => void)): void; 19 | declare function fdescribe(description: string, tests: (() => void)): void; 20 | declare function xdescribe(description: string, tests: (() => void)): void; 21 | declare function it(description: string, test: ((done: DoneCb) => void)): void; 22 | declare function xit(description: string, test: ((done: DoneCb) => void)): void; 23 | declare function fit(description: string, test: ((done: DoneCb) => void)): void; 24 | declare function expect(x: T): IExpectable; 25 | declare function fail(description: string): void; 26 | 27 | describe("Counters", () => { 28 | const counterConfig: MetricConfig = { 29 | name: "usage_total", 30 | help: "counts of usage, like times a feature has been used, etc", 31 | type: "counter", 32 | protocol: "prometheus", 33 | labels: [ 34 | { 35 | name: "browser", 36 | allowedValues: ["chrome", "firefox", "safari", "edge"] 37 | }, 38 | { 39 | name: "feature", 40 | allowedValues: [ 41 | "quickQuestion", 42 | "selfPacedMode", 43 | "blockStudent", 44 | "showContent" 45 | ] 46 | } 47 | ] 48 | }; 49 | 50 | it("has this test", () => { 51 | const counter = makeCounter(counterConfig, null); 52 | counter.record({ 53 | metricType: "counter", 54 | metricName: "usage_total", 55 | labels: { browser: "chrome", feature: "selfPacedMode" }, 56 | inc: 5 57 | }); 58 | 59 | counter.record({ 60 | metricType: "counter", 61 | metricName: "usage_total", 62 | labels: { browser: "firefox", feature: "selfPacedMode" }, 63 | inc: 3 64 | }); 65 | 66 | counter.record({ 67 | metricType: "counter", 68 | metricName: "usage_total", 69 | labels: { browser: "chrome", feature: "selfPacedMode" }, 70 | inc: 1 71 | }); 72 | 73 | const expected = `# HELP usage_total counts of usage, like times a feature has been used, etc 74 | # TYPE usage_total counter 75 | usage_total{browser="chrome",feature="quickQuestion"} 0 76 | usage_total{browser="chrome",feature="selfPacedMode"} 6 77 | usage_total{browser="chrome",feature="blockStudent"} 0 78 | usage_total{browser="chrome",feature="showContent"} 0 79 | usage_total{browser="firefox",feature="quickQuestion"} 0 80 | usage_total{browser="firefox",feature="selfPacedMode"} 3 81 | usage_total{browser="firefox",feature="blockStudent"} 0 82 | usage_total{browser="firefox",feature="showContent"} 0 83 | usage_total{browser="safari",feature="quickQuestion"} 0 84 | usage_total{browser="safari",feature="selfPacedMode"} 0 85 | usage_total{browser="safari",feature="blockStudent"} 0 86 | usage_total{browser="safari",feature="showContent"} 0 87 | usage_total{browser="edge",feature="quickQuestion"} 0 88 | usage_total{browser="edge",feature="selfPacedMode"} 0 89 | usage_total{browser="edge",feature="blockStudent"} 0 90 | usage_total{browser="edge",feature="showContent"} 0`; 91 | expect(counter.report()).toBe(expected); 92 | }); 93 | }); 94 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | orbs: 3 | datacamp-ecr: datacamp/ecr@1 4 | datacamp-deploy: datacamp/deploy@2 5 | queue: eddiewebb/queue@1.6.4 6 | datacamp-deploy-branch: datacamp/deploy-branch@1 7 | datacamp-artifactory: datacamp/artifactory@1 8 | workflows: 9 | # BEGIN ANSIBLE MANAGED BLOCK 10 | build-and-deploy-eks: 11 | jobs: 12 | - queue/block_workflow: 13 | name: queue 14 | context: org-global 15 | time: "10" 16 | filters: 17 | branches: 18 | ignore: 19 | - /backstage\/.*/ 20 | 21 | - datacamp-artifactory/build_and_push_image_to_artifactory: &dockerBuild 22 | name: docker-build 23 | context: org-global 24 | dockerfile: Dockerfile 25 | extra-docker-args: --build-arg NPM_TOKEN=$NPM_TOKEN --progress=plain 26 | repo: prometheus-aggregator 27 | docker-version: 20.10.2 28 | executor: datacamp-artifactory/buildkit 29 | requires: 30 | - queue 31 | 32 | - datacamp-artifactory/tag_repository: 33 | name: tag 34 | context: org-global 35 | requires: 36 | - docker-build 37 | - queue 38 | filters: 39 | branches: 40 | only: 41 | - master 42 | deploy-backstage: 43 | jobs: 44 | - datacamp-artifactory/build_and_push_image_to_artifactory: 45 | name: docker-build 46 | context: org-global 47 | dockerfile: apps/api/Dockerfile 48 | extra-docker-args: --build-arg NPM_TOKEN=$NPM_TOKEN --progress=plain 49 | docker-version: 20.10.2 50 | repo: prometheus-aggregator 51 | executor: datacamp-artifactory/buildkit 52 | filters: 53 | branches: 54 | only: 55 | - /backstage\/.*/ 56 | - datacamp-deploy-branch/deploy: # Backstage branch deploy 57 | name: deploy-to-backstage 58 | context: org-global 59 | app: grading 60 | env: staging 61 | roles: terraform-role,k8s-role 62 | region: us-east-1 63 | extra-vars: "backstage=true" 64 | filters: 65 | branches: 66 | only: 67 | - /backstage\/.*/ 68 | requires: 69 | - docker-build 70 | 71 | - testing-complete: # <<< Require a manual approval to cleandown 72 | type: approval 73 | requires: 74 | - deploy-to-backstage 75 | filters: 76 | branches: 77 | only: 78 | - /backstage\/.*/ 79 | 80 | - datacamp-deploy-branch/deploy: 81 | name: cleandown-backstage 82 | context: org-global 83 | app: grading 84 | env: staging 85 | roles: app-cleandown-role 86 | extra-vars: "backstage=true" 87 | filters: 88 | branches: 89 | only: 90 | - /backstage\/.*/ 91 | requires: 92 | - testing-complete 93 | # END ANSIBLE MANAGED BLOCK 94 | version: 2.1 95 | build_test_deploy: 96 | jobs: 97 | - datacamp-ecr/build_and_push_image_to_ecr: 98 | name: build 99 | context: org-global 100 | aws-access-key-id: $OPS_AWS_ACCESS_KEY_ID 101 | aws-secret-access-key: $OPS_AWS_SECRET_ACCESS_KEY 102 | account-url: $OPS_ECR_URL 103 | puller-account-ids: '["301258414863", "487088987264"]' 104 | extra-docker-args: "--build-arg NPM_TOKEN=${NPM_TOKEN}" 105 | 106 | - datacamp-deploy/deploy: # Staging 107 | name: deploy-staging 108 | context: org-global 109 | requires: 110 | - build 111 | filters: 112 | branches: 113 | only: 114 | - master 115 | # parameters 116 | aws-access-key-id: $STAGING_AWS_ACCESS_KEY_ID 117 | aws-secret-access-key: $STAGING_AWS_SECRET_ACCESS_KEY 118 | environment: staging 119 | 120 | - datacamp-deploy/deploy: # Production 121 | name: deploy-production 122 | context: org-global 123 | filters: 124 | tags: 125 | only: /^release-.*/ 126 | branches: 127 | ignore: /.*/ 128 | # parameters 129 | aws-access-key-id: $PROD_AWS_ACCESS_KEY_ID 130 | aws-secret-access-key: $PROD_AWS_SECRET_ACCESS_KEY 131 | environment: prod 132 | -------------------------------------------------------------------------------- /src/aggregators/__tests__/histogramTest.ts: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | import { makeHistogram } from "../histogram"; 3 | import { MetricConfig } from "../util"; 4 | 5 | declare interface IExpectable { 6 | toBe: (t: T) => void; 7 | toBeNull: () => void; 8 | toBeTruthy: () => void; 9 | toBeFalsy: () => void; 10 | toContain: (t: any) => void; 11 | toEqual: (t: T) => void; 12 | not: IExpectable; 13 | } 14 | 15 | declare type DoneCb = () => void; 16 | 17 | declare function beforeAll(prepare: ((done: DoneCb) => void)): void; 18 | declare function describe(description: string, tests: (() => void)): void; 19 | declare function fdescribe(description: string, tests: (() => void)): void; 20 | declare function xdescribe(description: string, tests: (() => void)): void; 21 | declare function it(description: string, test: ((done: DoneCb) => void)): void; 22 | declare function xit(description: string, test: ((done: DoneCb) => void)): void; 23 | declare function fit(description: string, test: ((done: DoneCb) => void)): void; 24 | declare function expect(x: T): IExpectable; 25 | declare function fail(description: string): void; 26 | 27 | describe("Histograms", () => { 28 | const histogramConfig: MetricConfig = { 29 | name: "firebase_response_time", 30 | help: "measures firebase response times in seconds", 31 | type: "histogram", 32 | protocol: "prometheus", 33 | labels: [ 34 | { 35 | name: "firebaseHost", 36 | allowedValues: ["pd-dev-1.firebaseio.com", "pd-dev-2.firebaseio.com"] 37 | } 38 | ], 39 | buckets: [0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100] 40 | }; 41 | 42 | it("has this test", () => { 43 | const histogram = makeHistogram(histogramConfig, null); 44 | 45 | histogram.record({ 46 | metricType: "histogram", 47 | metricName: "firebase_response_time", 48 | labels: { firebaseHost: "pd-dev-1.firebaseio.com" }, 49 | observations: [0.1, 1, 3] 50 | }); 51 | 52 | histogram.record({ 53 | metricType: "histogram", 54 | metricName: "firebase_response_time", 55 | labels: { firebaseHost: "pd-dev-1.firebaseio.com" }, 56 | observations: [5, 9, 2] 57 | }); 58 | 59 | histogram.record({ 60 | metricType: "histogram", 61 | metricName: "firebase_response_time", 62 | labels: { firebaseHost: "pd-dev-2.firebaseio.com" }, 63 | observations: [15, 19, 12] 64 | }); 65 | 66 | const expected = `# HELP firebase_response_time measures firebase response times in seconds 67 | # TYPE firebase_response_time histogram 68 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.05"} 0 69 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.1"} 1 70 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.2"} 1 71 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.5"} 1 72 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="1"} 2 73 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="2"} 3 74 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="5"} 5 75 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="10"} 6 76 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="20"} 6 77 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="50"} 6 78 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="100"} 6 79 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="+Inf"} 6 80 | firebase_response_time_sum{firebaseHost="pd-dev-1.firebaseio.com"} 20.1 81 | firebase_response_time_count{firebaseHost="pd-dev-1.firebaseio.com"} 6 82 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.05"} 0 83 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.1"} 0 84 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.2"} 0 85 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.5"} 0 86 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="1"} 0 87 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="2"} 0 88 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="5"} 0 89 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="10"} 0 90 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="20"} 3 91 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="50"} 3 92 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="100"} 3 93 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="+Inf"} 3 94 | firebase_response_time_sum{firebaseHost="pd-dev-2.firebaseio.com"} 46 95 | firebase_response_time_count{firebaseHost="pd-dev-2.firebaseio.com"} 3`; 96 | 97 | expect(histogram.report()).toBe(expected); 98 | }); 99 | }); 100 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # User Monitoring for Prometheus 2 | 3 | Prometheus, a [Cloud Native Computing Foundation](https://cncf.io/) project, is a systems and service monitoring system. *This* project provides the infrastructure you need to do end-user monitoring in Prometheus as well. 4 | 5 | ## Designed for use cases like: 6 | 7 | * Set alarms for spikes in page load times or error rates! 8 | * Measure real experienced latencies for API calls! 9 | * You don't control Firebase (insert your favorite third-party "serverless" thing here) but now you can monitor how your users are experiencing it! 10 | * Understand how much usage a newly-deployed feature is getting! 11 | * Use alarms as end-to-end tests by getting a slack message when a usage pattern changes dramatically! Automatically warn yourselves if your usage drops from last week - either overall or for a particular feature! 12 | * No need for third-party services that compromise your users' privacy or security! 13 | * Easy to set up and cheap to run! 14 | 15 | ## Try it locally! 16 | 17 | 1. Clone repo 18 | 2. `docker-compose up` 19 | 3. Browse to http://localhost:8080 20 | 21 | ## Pictures You Can Use to Impress Your Friends 22 | 23 | Github's Frontend Response Time Graph is a snap! We can literally generate this graph for you AND let you set alarms on it without any manual instrumentation on your part. See https://githubengineering.com/browser-monitoring-for-github-com/ for how Github uses these metrics. 24 | 25 | ![Github's Frontend Response Time Graph](https://cloud.githubusercontent.com/assets/187987/7738101/d9892654-ff05-11e4-8d62-340091dada79.png) 26 | 27 | Here's how the demo for this project loads the same graph: 28 | ![The graph from this project](/navigationtiming.png?raw=true) 29 | 30 | Wow, your super-cool Slack-ops channel can be even more glib about outages... NOW FOR THE END USER! 31 | ![Slack Ops](/SweetSlackOps.png?raw=true "Your users can't get their S3 photos, but your monitoring is pretty cool!") 32 | 33 | You don't control Firebase (insert your third-party "serverless" thing here) but now you can monitor how your users are experiencing it! 34 | 35 | ## How it works 36 | 37 | The challenge in monitoring your real users' experiences is that Prometheus can't scrape their clients, so this project adds a service that Prometheus CAN scrape, and provides an API that your clients can PUSH their metrics too. We provide client-side libraries to make that a snap. 38 | 39 | ![Prometheus User Monitoring Architecture Diagram](/PrometheusUserMonitoringArchitecture.png?raw=true "Prometheus User Monitoring Architecture") 40 | 41 | ## How to use it 42 | 43 | ### Server-side 44 | 45 | 1. Put the aggregator in your cloud. Prometheus will notice it automatically by its annotations! 46 | `kubectl apply -f prometheus-user-monitoring-aggregator.yaml` 47 | 48 | 2. Make a route through your gateway so clients can reach the aggregator. For testing it out, this could just be 49 | `kubectl port-forward $(kubectl get pod -l app=prometheus-user-monitoring-aggregator -o=jsonpath={.items[*].metadata.name}) 3000` 50 | 51 | ### Client-side (JS) 52 | 53 | 1. EZ-setup: just add this snippet to your HTML: 54 | 55 | ``` 56 | // copied from Google Analytics Snippet, adapted for Prometheus Aggregator 57 | (function(i,s,o,g,r,a,m){i['PrometheusAggregatorObjectName']=r;i[r]=i[r]||function(){ 58 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 59 | m=s.getElementsByTagName(o)[0];a.async=1;a.src=(g+'/static/aggregatorClient.js');m.parentNode.insertBefore(a,m); 60 | i[r].aggregatorServerRoot = g; 61 | })(window,document,'script','http://localhost:3000','prometheusAggregator'); 62 | ``` 63 | 64 | 65 | That's it! It's already collecting enough metrics to do github's user monitoring in the Sweet Graph above. If you want to collect custom metrics, then you'd need to add them to a whitelist. Once you have that set up (it's just a [config file](/config/metricConfigs/appMetricConfig.json)), then you can monitor metrics like: 66 | 67 | 1. How much does this page get loaded? 68 | ``` 69 | prometheusAggregator('increment', 'app_load_succeeded', { app: 'whateverAppId'}, 1); 70 | ``` 71 | 72 | 2. How many users are using the new feature we launched? 73 | ``` 74 | featureButton.on('click', () => { 75 | doFeatureX(); 76 | prometheusAggregator('increment', 'feature_usage_total', { feature: 'whateverFeatureName'}, 1); 77 | }); 78 | ``` 79 | 80 | 3. TODO: What's the average latency to a third-party service like firebase? 81 | ``` 82 | prometheusAggregator('observe', 'firebase_latency', { firebaseHost: 'whatever.firebaseio.com' }, measuredLatency) 83 | ``` 84 | 85 | The client aggregates all the metrics and sends them to the aggregator at an interval of X seconds. The aggregator automatically gains some notion of how many clients are connected with `rate(clientSamples) / X` 86 | 87 | ## The Future of this Project 88 | 89 | We use this in production at Pear Deck and it's pretty great. We don't know how widely applicable it is. Let us know by leaving an issue or starring the project! You can also email us at hello@peardeck.com. -------------------------------------------------------------------------------- /src/aggregators/histogram.ts: -------------------------------------------------------------------------------- 1 | import { StatsD } from "hot-shots"; 2 | 3 | import { 4 | flattenLabels, 5 | getLabelPermutations, 6 | IHistogramEvent, 7 | IHistogramMetric, 8 | IHistogramMetricPrometheus, 9 | IHistogramMetricStatsd, 10 | ILabel 11 | } from "./util"; 12 | 13 | interface IHistogramObservationAggregate { 14 | buckets: { [bucketLimit: string]: number }; // Note, "+Inf" won't be kept in here. We'll just report `sum` as +Inf synthetically when printing this aggregate. 15 | sum: number; 16 | count: number; 17 | } 18 | 19 | function addObservation( 20 | aggregate: IHistogramObservationAggregate, 21 | newObservation: number 22 | ) { 23 | Object.keys(aggregate.buckets).forEach(bucketLimit => { 24 | if (newObservation <= Number(bucketLimit)) { 25 | aggregate.buckets[bucketLimit] += 1; 26 | } 27 | }); 28 | 29 | aggregate.count += 1; 30 | aggregate.sum += newObservation; 31 | } 32 | 33 | function printObservationAggregate( 34 | metricName: string, 35 | labelPermutationKey: string, 36 | aggregate: IHistogramObservationAggregate 37 | ) { 38 | const leKeys = Object.keys(aggregate.buckets).sort( 39 | (a, b) => (Number(a) < Number(b) ? -1 : 1) 40 | ); 41 | const labelStringPrefix = 42 | labelPermutationKey.length > 0 43 | ? `${labelPermutationKey},` // stick labels in front of new `le` label with a comma 44 | : ""; // no labels, no comma. 45 | 46 | const bucketLines = leKeys.map(bucketLimit => { 47 | return `${metricName}_bucket{${labelStringPrefix}le="${bucketLimit}"} ${ 48 | aggregate.buckets[bucketLimit] 49 | }`; 50 | }); 51 | 52 | return ( 53 | bucketLines.join("\n") + 54 | "\n" + 55 | `${metricName}_bucket{${labelStringPrefix}le="+Inf"} ${aggregate.count}` + 56 | "\n" + 57 | `${metricName}_sum{${labelPermutationKey}} ${aggregate.sum}` + 58 | "\n" + 59 | `${metricName}_count{${labelPermutationKey}} ${aggregate.count}` 60 | ); 61 | } 62 | 63 | export interface IHistogram { 64 | record: (event: IHistogramEvent) => void; 65 | report: () => string; 66 | } 67 | 68 | export function makeHistogram( 69 | config: IHistogramMetric, 70 | statsdClient: StatsD 71 | ): IHistogram { 72 | const { help, type, protocol } = config; 73 | const name = `${protocol}.${config.name}`; 74 | const client = statsdClient; 75 | 76 | const allowedLabelPermutations = getLabelPermutations(config.labels); 77 | 78 | const mapOfAggregates: { [key: string]: IHistogramObservationAggregate } = {}; 79 | 80 | allowedLabelPermutations.forEach(permutation => { 81 | // initialize all allowed permutations to a bunch of empty buckets. 82 | const initializedAggregate: IHistogramObservationAggregate = { 83 | buckets: {}, 84 | sum: 0, 85 | count: 0 86 | }; 87 | 88 | if (protocol === "prometheus") { 89 | const pConfig = config as IHistogramMetricPrometheus; 90 | pConfig.buckets.forEach(bucketLimit => { 91 | initializedAggregate.buckets[bucketLimit.toString()] = 0; 92 | }); 93 | } 94 | 95 | mapOfAggregates[permutation] = initializedAggregate; 96 | 97 | // later, all other permutations will be rejected, so this 98 | // secures the counters against misbehaving clients who would 99 | // send unknown labels or values and crash poor prometheus. 100 | }); 101 | 102 | const recordPrometheus = (event: IHistogramEvent) => { 103 | const labelPermutationKey = flattenLabels(event.labels); 104 | if (mapOfAggregates[labelPermutationKey]) { 105 | event.observations.forEach(observation => { 106 | addObservation(mapOfAggregates[labelPermutationKey], observation); 107 | }); 108 | } else { 109 | console.log(`Disallowed label permutation ${labelPermutationKey}`); 110 | } 111 | }; 112 | 113 | const recordStatsd = (event: IHistogramEvent) => { 114 | event.observations.forEach(observation => { 115 | client.histogram(name, observation, event.labels); 116 | }); 117 | }; 118 | 119 | return { 120 | record(event: IHistogramEvent) { 121 | if (protocol === "statsd") { 122 | recordStatsd(event); 123 | } else if (protocol === "prometheus") { 124 | recordPrometheus(event); 125 | } else { 126 | console.log(`Unknown protocol: ${protocol}`); 127 | } 128 | }, 129 | 130 | report() { 131 | if (protocol === "prometheus") { 132 | const headerLines = [ 133 | `# HELP ${name} ${help}`, 134 | `# TYPE ${name} ${type}` 135 | ]; 136 | 137 | const bodyLines = Object.keys(mapOfAggregates).map( 138 | labelPermutationKey => { 139 | const aggregate = mapOfAggregates[labelPermutationKey]; 140 | return printObservationAggregate( 141 | name, 142 | labelPermutationKey, 143 | aggregate 144 | ); 145 | } 146 | ); 147 | 148 | return headerLines.join("\n") + "\n" + bodyLines.join("\n"); 149 | } 150 | return ""; 151 | } 152 | }; 153 | } 154 | -------------------------------------------------------------------------------- /config/metricConfigs/workspaceMetrics.ts: -------------------------------------------------------------------------------- 1 | import { MetricsConfig } from '../../src/aggregators/util'; 2 | 3 | const allowedMetrics: MetricsConfig = [ 4 | { 5 | name: "workspace_time_to_session_loaded", 6 | help: "measures the time between session started and editor loaded", 7 | type: "histogram", 8 | labels: [ 9 | { 10 | name: "editor", 11 | allowedValues: ["JupyterLab", "RStudio"] 12 | }, 13 | { 14 | name: "editorType", 15 | allowedValues: ["iframeEditor", "dcStudioEditor"] 16 | }, 17 | { 18 | name: "workspaceState", 19 | allowedValues: ["unknown", "new", "existing"] 20 | } 21 | ], 22 | protocol: "statsd" 23 | }, 24 | { 25 | name: "workspace_time_to_session_ready_for_editor_start", 26 | help: "measures the time between session started and editor loaded", 27 | type: "distribution", 28 | labels: [ 29 | { 30 | name: "editor", 31 | allowedValues: ["JupyterLab", "RStudio"] 32 | }, 33 | { 34 | name: "editorType", 35 | allowedValues: ["iframeEditor", "dcStudioEditor"] 36 | }, 37 | { 38 | name: "workspaceState", 39 | allowedValues: ["unknown", "new", "existing"] 40 | } 41 | ], 42 | protocol: "statsd" 43 | }, 44 | { 45 | name: "workspace_count_crashed_sessions", 46 | help: "The amount of sessions that crashed", 47 | type: "counter", 48 | labels: [ 49 | { 50 | name: "editor", 51 | allowedValues: ["JupyterLab", "RStudio"] 52 | } 53 | ], 54 | protocol: "statsd" 55 | }, 56 | { 57 | name: "workspace_count_restart_sessions", 58 | help: "The amount of sessions that restarted in DCStudio", 59 | type: "counter", 60 | labels: [ 61 | { 62 | name: "mode", 63 | allowedValues: ["executing", "viewing", "editing"] 64 | }, 65 | { 66 | name: "reason", 67 | allowedValues: [ 68 | "unknown", 69 | "loading", 70 | "no-saving", 71 | "not-allowed", 72 | "offline", 73 | "context-not-ready", 74 | "kernel-broken", 75 | "no-context", 76 | "no-kernel", 77 | "session-broken" 78 | ] 79 | } 80 | ], 81 | protocol: "statsd" 82 | }, 83 | { 84 | name: "workspace_time_to_initial_content_render_start", 85 | help: "measures the time to render any content of a workspace", 86 | type: "distribution", 87 | labels: [ 88 | { 89 | name: "navigationType", 90 | allowedValues: ["unknown", "initial", "client-side"] 91 | }, 92 | { 93 | name: "workspaceState", 94 | allowedValues: ["unknown", "new", "existing"] 95 | }, 96 | { 97 | name: "experimentalSyncBackend", 98 | allowedValues: ["true", "false"] 99 | } 100 | ], 101 | protocol: "statsd" 102 | }, 103 | { 104 | name: "workspace_cpu_usage", 105 | help: "measures the cpu usage of a workspace", 106 | type: "distribution", 107 | labels: [ 108 | { 109 | name: "accountReferenceType", 110 | allowedValues: ["group", "personal"] 111 | }, 112 | { 113 | name: "isPremium", 114 | allowedValues: ["true", "false"] 115 | }, 116 | { 117 | name: "isNotebookRunning", 118 | allowedValues: ["true", "false"] 119 | }, 120 | { 121 | name: "language", 122 | allowedValues: ["R", "Python"] 123 | }, 124 | { 125 | name: "sourceTag", 126 | allowedValues: ["workspace", "integration", "template", "github", "project", "rdocs"] 127 | } 128 | ], 129 | protocol: "statsd" 130 | }, 131 | { 132 | name: "workspace_ram_usage", 133 | help: "measures the ram usage of a workspace", 134 | type: "distribution", 135 | labels: [ 136 | { 137 | name: "accountReferenceType", 138 | allowedValues: ["group", "personal"] 139 | }, 140 | { 141 | name: "isPremium", 142 | allowedValues: ["true", "false"] 143 | }, 144 | { 145 | name: "isNotebookRunning", 146 | allowedValues: ["true", "false"] 147 | }, 148 | { 149 | name: "language", 150 | allowedValues: ["R", "Python"] 151 | }, 152 | { 153 | name: "sourceTag", 154 | allowedValues: ["workspace", "integration", "template", "github", "project", "rdocs"] 155 | } 156 | ], 157 | protocol: "statsd" 158 | }, 159 | { 160 | name: "workspace_time_to_load_dashboard", 161 | help: "measures the time to render completely the dashboard", 162 | type: "distribution", 163 | labels: [], 164 | protocol: "statsd" 165 | }, 166 | { 167 | name: "workspace_time_to_load_publication", 168 | help: "measures the time to render completely a publication", 169 | type: "distribution", 170 | labels: [], 171 | protocol: "statsd" 172 | }, 173 | { 174 | name: "workspace_time_to_load_editor", 175 | help: "measures the time to render the first cell in DCStudio", 176 | type: "distribution", 177 | labels: [], 178 | protocol: "statsd" 179 | }, 180 | { 181 | name: "workspace_count_show_limit_cpu_ram_usage", 182 | help: "the amount of times users were shown the CPU/RAM limit usage banner in a workspace", 183 | type: "counter", 184 | labels: [ 185 | { 186 | name: "resource", 187 | allowedValues: ["CPU", "RAM"] 188 | } 189 | ], 190 | protocol: "statsd" 191 | }, 192 | ]; 193 | 194 | export default allowedMetrics; 195 | -------------------------------------------------------------------------------- /src/__tests__/reportingTests.js: -------------------------------------------------------------------------------- 1 | import { makeAggregator } from '../makeMetricsAggregator'; 2 | 3 | const exampleConfig = [ 4 | { 5 | "name": "usage_total", 6 | "help": "counts of usage, like times a feature has been used, etc", 7 | "type": "counter", 8 | "labels": [ 9 | { 10 | "name": "browser", 11 | "allowedValues": [ 12 | "chrome", 13 | "firefox", 14 | "safari", 15 | "edge" 16 | ] 17 | }, 18 | { 19 | "name": "feature", 20 | "allowedValues": [ 21 | "quickQuestion", 22 | "selfPacedMode", 23 | "blockStudent", 24 | "showContent" 25 | ] 26 | } 27 | ] 28 | }, 29 | { 30 | "name": "firebase_response_time", 31 | "help": "measures firebase response times in seconds", 32 | "type": "histogram", 33 | "labels": [ 34 | { 35 | "name": "firebaseHost", 36 | "allowedValues": [ 37 | "pd-dev-1.firebaseio.com", 38 | "pd-dev-2.firebaseio.com" 39 | ] 40 | } 41 | ], 42 | "buckets": [ 43 | 0.05, 44 | 0.1, 45 | 0.2, 46 | 0.5, 47 | 1, 48 | 2, 49 | 5, 50 | 10, 51 | 20, 52 | 50, 53 | 100 54 | ] 55 | } 56 | ]; 57 | 58 | function outputWithUsageTotal(usageTotal) { 59 | return `# HELP usage_total counts of usage, like times a feature has been used, etc 60 | # TYPE usage_total counter 61 | usage_total{browser="chrome",feature="quickQuestion"} ${usageTotal} 62 | usage_total{browser="chrome",feature="selfPacedMode"} 0 63 | usage_total{browser="chrome",feature="blockStudent"} 0 64 | usage_total{browser="chrome",feature="showContent"} 0 65 | usage_total{browser="firefox",feature="quickQuestion"} 0 66 | usage_total{browser="firefox",feature="selfPacedMode"} 0 67 | usage_total{browser="firefox",feature="blockStudent"} 0 68 | usage_total{browser="firefox",feature="showContent"} 0 69 | usage_total{browser="safari",feature="quickQuestion"} 0 70 | usage_total{browser="safari",feature="selfPacedMode"} 0 71 | usage_total{browser="safari",feature="blockStudent"} 0 72 | usage_total{browser="safari",feature="showContent"} 0 73 | usage_total{browser="edge",feature="quickQuestion"} 0 74 | usage_total{browser="edge",feature="selfPacedMode"} 0 75 | usage_total{browser="edge",feature="blockStudent"} 0 76 | usage_total{browser="edge",feature="showContent"} 0 77 | # HELP firebase_response_time measures firebase response times in seconds 78 | # TYPE firebase_response_time histogram 79 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.05"} 0 80 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.1"} 0 81 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.2"} 0 82 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.5"} 0 83 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="1"} 0 84 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="2"} 0 85 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="5"} 0 86 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="10"} 0 87 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="20"} 0 88 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="50"} 0 89 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="100"} 0 90 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="+Inf"} 0 91 | firebase_response_time_sum{firebaseHost="pd-dev-1.firebaseio.com"} 0 92 | firebase_response_time_count{firebaseHost="pd-dev-1.firebaseio.com"} 0 93 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.05"} 0 94 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.1"} 0 95 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.2"} 0 96 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.5"} 0 97 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="1"} 0 98 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="2"} 0 99 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="5"} 0 100 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="10"} 0 101 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="20"} 0 102 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="50"} 0 103 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="100"} 0 104 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="+Inf"} 0 105 | firebase_response_time_sum{firebaseHost="pd-dev-2.firebaseio.com"} 0 106 | firebase_response_time_count{firebaseHost="pd-dev-2.firebaseio.com"} 0 107 | `; 108 | } 109 | 110 | const usageTotalKey = 'usage_total{browser="chrome",feature="quickQuestion"}'; 111 | 112 | describe('Aggregator reporting', () => { 113 | it('prints a correct default', () => { 114 | const aggregator = makeAggregator(exampleConfig); 115 | expect(aggregator.reportMetrics()).toBe(outputWithUsageTotal(0)); 116 | }); 117 | 118 | it('correctly increments uninitialized counters', () => { 119 | const aggregator = makeAggregator(exampleConfig); 120 | aggregator.consume({ 121 | metricName: 'usage_total', 122 | metricType: 'counter', 123 | labels: { 124 | browser: 'chrome', 125 | feature: 'quickQuestion', 126 | }, 127 | inc: 3.5 128 | }); 129 | 130 | expect(aggregator.reportMetrics()).toBe(outputWithUsageTotal(3.5)); 131 | }); 132 | 133 | it('correctly increments initialized counters', () => { 134 | const aggregator = makeAggregator(exampleConfig); 135 | aggregator.consume({ 136 | metricName: 'usage_total', 137 | metricType: 'counter', 138 | labels: { 139 | browser: 'chrome', 140 | feature: 'quickQuestion', 141 | }, 142 | inc: 3.5 143 | }); 144 | aggregator.consume({ 145 | metricName: 'usage_total', 146 | metricType: 'counter', 147 | labels: { 148 | browser: 'chrome', 149 | feature: 'quickQuestion', 150 | }, 151 | inc: 3.5 152 | }); 153 | expect(aggregator.reportMetrics()).toBe(outputWithUsageTotal(7)); 154 | }); 155 | 156 | it('correctly records observations of histograms', () => { 157 | const aggregator = makeAggregator(exampleConfig); 158 | 159 | const expected = `# HELP usage_total counts of usage, like times a feature has been used, etc 160 | # TYPE usage_total counter 161 | usage_total{browser="chrome",feature="quickQuestion"} 0 162 | usage_total{browser="chrome",feature="selfPacedMode"} 0 163 | usage_total{browser="chrome",feature="blockStudent"} 0 164 | usage_total{browser="chrome",feature="showContent"} 0 165 | usage_total{browser="firefox",feature="quickQuestion"} 0 166 | usage_total{browser="firefox",feature="selfPacedMode"} 0 167 | usage_total{browser="firefox",feature="blockStudent"} 0 168 | usage_total{browser="firefox",feature="showContent"} 0 169 | usage_total{browser="safari",feature="quickQuestion"} 0 170 | usage_total{browser="safari",feature="selfPacedMode"} 0 171 | usage_total{browser="safari",feature="blockStudent"} 0 172 | usage_total{browser="safari",feature="showContent"} 0 173 | usage_total{browser="edge",feature="quickQuestion"} 0 174 | usage_total{browser="edge",feature="selfPacedMode"} 0 175 | usage_total{browser="edge",feature="blockStudent"} 0 176 | usage_total{browser="edge",feature="showContent"} 0 177 | # HELP firebase_response_time measures firebase response times in seconds 178 | # TYPE firebase_response_time histogram 179 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.05"} 1 180 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.1"} 2 181 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.2"} 2 182 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="0.5"} 3 183 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="1"} 3 184 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="2"} 3 185 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="5"} 3 186 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="10"} 3 187 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="20"} 3 188 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="50"} 3 189 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="100"} 3 190 | firebase_response_time_bucket{firebaseHost="pd-dev-1.firebaseio.com",le="+Inf"} 3 191 | firebase_response_time_sum{firebaseHost="pd-dev-1.firebaseio.com"} 0.45 192 | firebase_response_time_count{firebaseHost="pd-dev-1.firebaseio.com"} 3 193 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.05"} 0 194 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.1"} 0 195 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.2"} 0 196 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="0.5"} 0 197 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="1"} 0 198 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="2"} 0 199 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="5"} 0 200 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="10"} 0 201 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="20"} 0 202 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="50"} 0 203 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="100"} 0 204 | firebase_response_time_bucket{firebaseHost="pd-dev-2.firebaseio.com",le="+Inf"} 0 205 | firebase_response_time_sum{firebaseHost="pd-dev-2.firebaseio.com"} 0 206 | firebase_response_time_count{firebaseHost="pd-dev-2.firebaseio.com"} 0 207 | `; 208 | 209 | aggregator.consume({ 210 | metricName: 'firebase_response_time', 211 | metricType: 'histogram', 212 | labels: { 213 | firebaseHost: 'pd-dev-1.firebaseio.com', 214 | }, 215 | observations: [0.1, 0.3, 0.05] 216 | }); 217 | 218 | expect(aggregator.reportMetrics()).toBe(expected); 219 | }) 220 | }); -------------------------------------------------------------------------------- /config/metricConfigs/learnMetrics.ts: -------------------------------------------------------------------------------- 1 | import { MetricsConfig } from "../../src/aggregators/util"; 2 | 3 | const allowedMetrics: MetricsConfig = [ 4 | { 5 | name: "le_count_crashed_sessions", 6 | help: "Count the number of sessions that crashed", 7 | type: "counter", 8 | labels: [ 9 | { 10 | name: "appName", 11 | allowedValues: ["campus-app"] 12 | }, 13 | { 14 | name: "multiplexerUrl", 15 | allowedValues: [ 16 | "https://multiplexer-prod.datacamp.com", 17 | "https://multiplexer-paid.datacamp.com" 18 | ] 19 | } 20 | ], 21 | protocol: "statsd" 22 | }, 23 | { 24 | name: "le_time_workspace_to_be_ready", 25 | help: "measures the time to get the workspace ready for a user", 26 | type: "histogram", 27 | labels: [ 28 | { 29 | name: "appName", 30 | allowedValues: ["campus-app", "projects"] 31 | }, 32 | { 33 | name: "multiplexerUrl", 34 | allowedValues: [ 35 | "https://multiplexer-prod.datacamp.com", 36 | "https://multiplexer-paid.datacamp.com" 37 | ] 38 | }, 39 | { 40 | name: "language", 41 | allowedValues: ["r", "revo", "sql", "python", "shell"] 42 | } 43 | ], 44 | protocol: "statsd" 45 | }, 46 | { 47 | name: "le_time_to_submit_code", 48 | help: "measures the time to submit a code and get the response", 49 | type: "histogram", 50 | labels: [ 51 | { 52 | name: "appName", 53 | allowedValues: ["campus-app"] 54 | }, 55 | { 56 | name: "multiplexerUrl", 57 | allowedValues: [ 58 | "https://multiplexer-prod.datacamp.com", 59 | "https://multiplexer-paid.datacamp.com" 60 | ] 61 | }, 62 | { 63 | name: "language", 64 | allowedValues: ["r", "revo", "sql", "python", "shell"] 65 | } 66 | ], 67 | protocol: "statsd" 68 | }, 69 | { 70 | name: "le_count_report_sent", 71 | help: "Count the number of reports reported", 72 | type: "counter", 73 | labels: [ 74 | { 75 | name: "appName", 76 | allowedValues: ["campus-app", "projects"] 77 | } 78 | ], 79 | protocol: "statsd" 80 | }, 81 | { 82 | name: "le_time_to_submit_task", 83 | help: "measures the time to submit a task and get the response", 84 | type: "histogram", 85 | labels: [ 86 | { 87 | name: "appName", 88 | allowedValues: ["projects"] 89 | }, 90 | { 91 | name: "multiplexerUrl", 92 | allowedValues: [ 93 | "https://multiplexer-prod.datacamp.com", 94 | "https://multiplexer-paid.datacamp.com" 95 | ] 96 | }, 97 | { 98 | name: "language", 99 | allowedValues: ["r", "revo", "sql", "python", "shell"] 100 | } 101 | ], 102 | protocol: "statsd" 103 | }, 104 | { 105 | name: "le_count_timeouts", 106 | help: "Count the number of timeouts", 107 | type: "counter", 108 | labels: [ 109 | { 110 | name: "appName", 111 | allowedValues: ["projects"] 112 | }, 113 | { 114 | name: "multiplexerUrl", 115 | allowedValues: [ 116 | "https://multiplexer-prod.datacamp.com", 117 | "https://multiplexer-paid.datacamp.com" 118 | ] 119 | }, 120 | { 121 | name: "language", 122 | allowedValues: ["r", "revo", "sql", "python", "shell"] 123 | } 124 | ], 125 | protocol: "statsd" 126 | }, 127 | { 128 | name: "le_count_crashed_notebooks", 129 | help: "Count the number of notebooks that crashed", 130 | type: "counter", 131 | labels: [ 132 | { 133 | name: "appName", 134 | allowedValues: ["projects"] 135 | }, 136 | { 137 | name: "multiplexerUrl", 138 | allowedValues: [ 139 | "https://multiplexer-prod.datacamp.com", 140 | "https://multiplexer-paid.datacamp.com" 141 | ] 142 | } 143 | ], 144 | protocol: "statsd" 145 | }, 146 | { 147 | name: "count_failed_auth_call", 148 | help: "Count the number of failed authentication calls", 149 | type: "counter", 150 | labels: [ 151 | { 152 | name: "appName", 153 | allowedValues: ["campus-app"] 154 | }, 155 | { 156 | name: "status_code", 157 | allowedValues: ["none", "200", "400", "403", "404", "500", "502", "503", "504", "untracked"] 158 | }, 159 | { 160 | name: "timeout", 161 | allowedValues: ["true", "false"] 162 | }, 163 | { 164 | name: "attempt", 165 | allowedValues: ["1", "2"] 166 | }, 167 | ], 168 | protocol: "statsd" 169 | }, 170 | { 171 | name: "learn_hub__time_to_initial_dashboard_load", 172 | help: "Measure the time to initial data load on the learn hub dashboard", 173 | type: "histogram", 174 | labels: [ 175 | { 176 | name: "appName", 177 | allowedValues: ["/learn"] 178 | }, 179 | { 180 | name: "pageName", 181 | allowedValues: ["dashboard"] 182 | }, 183 | { 184 | name: "underThreshold", 185 | allowedValues: ["true", "false"] 186 | }, 187 | ], 188 | protocol: "statsd" 189 | }, 190 | { 191 | name: "learn_hub__widget_loaded", 192 | help: "Count the widgets loaded on the learn hub dashboard and notify of any errors", 193 | type: "counter", 194 | labels: [ 195 | { 196 | name: "appName", 197 | allowedValues: ["/learn"] 198 | }, 199 | { 200 | name: "status", 201 | allowedValues: ["success", "failure"] 202 | }, 203 | { 204 | name: "widgetName", 205 | allowedValues: ["StreaksWidget", "CoursesWidget", "PracticeWidget", "ProjectWidget", "AssessmentWidget", "MyCoursesWidget", "SecondaryAlpaWidget"] 206 | }, 207 | ], 208 | protocol: "statsd" 209 | }, 210 | { 211 | name: "competitions__time_to_initial_explore_page_load", 212 | help: "Measure the time for competitions explore page load", 213 | type: "histogram", 214 | labels: [ 215 | { 216 | name: "appName", 217 | allowedValues: ["/learn/competitions"] 218 | }, 219 | { 220 | name: "pageName", 221 | allowedValues: ["explorePage"] 222 | }, 223 | { 224 | name: "underThreshold", 225 | allowedValues: ["true", "false"] 226 | }, 227 | ], 228 | protocol: "statsd" 229 | }, 230 | { 231 | name: "competitions__time_to_initial_details_page_load", 232 | help: "Measure the time for competitions details page load", 233 | type: "histogram", 234 | labels: [ 235 | { 236 | name: "appName", 237 | allowedValues: ["/learn/competitions"] 238 | }, 239 | { 240 | name: "pageName", 241 | allowedValues: ["detailsPage"] 242 | }, 243 | { 244 | name: "underThreshold", 245 | allowedValues: ["true", "false"] 246 | }, 247 | ], 248 | protocol: "statsd" 249 | }, 250 | { 251 | name: "competitions__time_to_entries_page_load", 252 | help: "Measure the time for competitions details page load", 253 | type: "histogram", 254 | labels: [ 255 | { 256 | name: "appName", 257 | allowedValues: ["/learn/competitions"] 258 | }, 259 | { 260 | name: "pageName", 261 | allowedValues: ["detailsPage"] 262 | }, 263 | { 264 | name: "underThreshold", 265 | allowedValues: ["true", "false"] 266 | }, 267 | ], 268 | protocol: "statsd" 269 | }, 270 | { 271 | name: "learn_hub__ad_loaded", 272 | help: "Count the ads loaded on the learn hub dashboard and notify of any errors", 273 | type: "counter", 274 | labels: [ 275 | { 276 | name: "appName", 277 | allowedValues: ["/learn"] 278 | }, 279 | { 280 | name: "status", 281 | allowedValues: ["success", "failure"] 282 | }, 283 | { 284 | name: "widgetName", 285 | allowedValues: ["SitewidePromoWidget", "TopAdWidget"] 286 | }, 287 | ], 288 | protocol: "statsd" 289 | }, 290 | { 291 | name: "campus__time_to_vm_session_load", 292 | help: "Measure the time for vm session to load", 293 | type: "histogram", 294 | labels: [ 295 | { 296 | name: "appName", 297 | allowedValues: ["campus-app"] 298 | }, 299 | { 300 | name: "technology", 301 | allowedValues: ["powerbi", "tableau", "other"] 302 | }, 303 | { 304 | name: "underThreshold", 305 | allowedValues: ["true", "false"] 306 | }, 307 | ], 308 | protocol: "statsd" 309 | }, 310 | { 311 | name: "campus__vm_session_start", 312 | help: "Count the vm session starts using exercise library", 313 | type: "counter", 314 | labels: [ 315 | { 316 | name: "appName", 317 | allowedValues: ["campus-app"] 318 | }, 319 | ], 320 | protocol: "statsd" 321 | }, 322 | { 323 | name: "campus__vm_session_disconnect", 324 | help: "Count the vm session disconnects using exercise library", 325 | type: "counter", 326 | labels: [ 327 | { 328 | name: "appName", 329 | allowedValues: ["campus-app"] 330 | }, 331 | ], 332 | protocol: "statsd" 333 | }, 334 | { 335 | name: "campus__vm_session_death", 336 | help: "Count the vm session deaths using exercise library", 337 | type: "counter", 338 | labels: [ 339 | { 340 | name: "appName", 341 | allowedValues: ["campus-app"] 342 | }, 343 | ], 344 | protocol: "statsd" 345 | }, 346 | { 347 | name: "campus__multiplexer_session_crash", 348 | help: "Count the number of multiplexer sessions that crashed", 349 | type: "counter", 350 | labels: [ 351 | { 352 | name: "appName", 353 | allowedValues: ["campus-app"] 354 | }, 355 | { 356 | name: "errorCode", 357 | allowedValues: [ 358 | "ActivityReadTimeout", 359 | "ActivityTimeout", 360 | "ActivityWriteTimeout", 361 | "CodeTimedOut", 362 | "DockerCrashed", 363 | "DockerFailedToRun", 364 | "Expired", 365 | "ExplicitlyStopped", 366 | "FailedToGetSession", 367 | "InitCodeTimedOut", 368 | "NotUsed", 369 | "OtherSessionRequested", 370 | "OtherSessionStarted", 371 | "ReplClosed", 372 | "WrongSessionType", 373 | ] 374 | }, 375 | ], 376 | protocol: "statsd" 377 | }, 378 | { 379 | name: "le_count_exercise_session_ready", 380 | help: "Count the number of multiplexer sessions that started", 381 | type: "counter", 382 | labels: [], 383 | protocol: "statsd" 384 | }, 385 | { 386 | name: "le_count_exercise_start", 387 | help: "Count the number of exercises started", 388 | type: "counter", 389 | labels: [], 390 | protocol: "statsd" 391 | }, 392 | { 393 | name: "campus__time_to_submit_code", 394 | help: "measures the time to submit a code and get the response", 395 | type: "distribution", 396 | labels: [], 397 | protocol: "statsd" 398 | }, 399 | ]; 400 | 401 | export default allowedMetrics; 402 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------