From e5187ff4c5511d410b0a5c213d17cfe3d32d3d37 Mon Sep 17 00:00:00 2001 From: geek Date: Wed, 16 Aug 2017 16:14:36 -0500 Subject: [PATCH] feat: support metrics in schema and mock server --- .../cp-gql-mock-server/src/metric-data.json | 56 +++++++++++++++++++ packages/cp-gql-mock-server/src/resolvers.js | 8 ++- packages/cp-gql-schema/schema.gql | 21 +++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 packages/cp-gql-mock-server/src/metric-data.json diff --git a/packages/cp-gql-mock-server/src/metric-data.json b/packages/cp-gql-mock-server/src/metric-data.json new file mode 100644 index 00000000..62aae529 --- /dev/null +++ b/packages/cp-gql-mock-server/src/metric-data.json @@ -0,0 +1,56 @@ +[ + { + "name": "AVG_MEM_BYTES", + "instance": "joyentportal_compose-api_1", + "metrics": [ + { + "time": "2017-08-16T15:10:17.371Z", + "value": 60518400 + }, + { + "time": "2017-08-16T16:10:17.371Z", + "value": 60641280 + }, + { + "time": "2017-08-16T17:10:17.371Z", + "value": 60575744 + } + ] + }, + { + "name": "AVG_LOAD_PERCENT", + "instance": "joyentportal_compose-api_1", + "metrics": [ + { + "time": "2017-08-16T15:10:17.371Z", + "value": 23.2 + }, + { + "time": "2017-08-16T16:10:17.371Z", + "value": 23.6 + }, + { + "time": "2017-08-16T17:10:17.371Z", + "value": 23.7 + } + ] + }, + { + "name": "AGG_NETWORK_BYTES", + "instance": "joyentportal_compose-api_1", + "metrics": [ + { + "time": "2017-08-16T15:10:17.371Z", + "value": 64262042 + }, + { + "time": "2017-08-16T16:10:17.371Z", + "value": 65743772 + }, + { + "time": "2017-08-16T17:10:17.371Z", + "value": 67226695 + } + ] + } +] \ No newline at end of file diff --git a/packages/cp-gql-mock-server/src/resolvers.js b/packages/cp-gql-mock-server/src/resolvers.js index 765b5a83..04b840e0 100644 --- a/packages/cp-gql-mock-server/src/resolvers.js +++ b/packages/cp-gql-mock-server/src/resolvers.js @@ -15,6 +15,7 @@ const Boom = require('boom'); const wpData = require('./wp-data.json'); const cpData = require('./cp-data.json'); const complexData = require('./complex-data.json'); +const metricData = require('./metric-data.json'); const { datacenter, portal } = require('./data.json'); @@ -527,6 +528,10 @@ const config = ({ return _plain ? config : Promise.resolve(config); }; +const getMetrics = () => { + return Promise.resolve(metricData); +}; + module.exports = { portal: getPortal, deploymentGroups: getDeploymentGroups, @@ -549,5 +554,6 @@ module.exports = { restartServices: (options, request, fn) => fn(null, restartServices(options)), stopServices: (options, request, fn) => fn(null, stopServices(options)), startServices: (options, request, fn) => fn(null, startServices(options)), - config + config, + metrics: getMetrics }; diff --git a/packages/cp-gql-schema/schema.gql b/packages/cp-gql-schema/schema.gql index c03b6b6c..0e658f2b 100644 --- a/packages/cp-gql-schema/schema.gql +++ b/packages/cp-gql-schema/schema.gql @@ -183,6 +183,25 @@ type Datacenter { region: String! } + +type Metric { + time: String! + value: Float! +} + +enum MetricName { + AVG_MEM_BYTES, + AVG_LOAD_PERCENT, + AGG_NETWORK_BYTES +} + +type InstanceMetric { + instance: String! + name: MetricName! + metrics: [Metrics] +} + + # we probably wont use some of these queries or arguments # but this way we expose the entire db through gql type Query { @@ -243,6 +262,8 @@ type Query { raw: String! ): [Service] importableDeploymentGroups: [DeploymentGroup] + # start and end should be .toISOString() date strings + metrics(names: [MerticName], instances: [String], start: String, end: String): [InstanceMetric] } type Mutation {