mirror of
https://github.com/yldio/copilot.git
synced 2024-11-28 06:00:06 +02:00
feat(cp-gql-mock-server, cp-gql-schema): Metrics to be a filed on instances (#607)
This commit is contained in:
parent
06fe7e1312
commit
ce31f505a0
@ -40,8 +40,36 @@ const find = (query = {}) => item =>
|
||||
|
||||
const cleanQuery = (q = {}) => JSON.parse(JSON.stringify(q));
|
||||
|
||||
const getMetrics = query => {
|
||||
const {
|
||||
names,
|
||||
start,
|
||||
end
|
||||
} = query;
|
||||
|
||||
const metrics = names.reduce((metrics, name) =>
|
||||
metrics.concat(metricData.filter(md =>
|
||||
md.name === name)), []);
|
||||
|
||||
return Promise.resolve(metrics);
|
||||
}
|
||||
|
||||
const getInstances = query => {
|
||||
return Promise.resolve(instances.filter(find(cleanQuery(query))));
|
||||
const metricsResolver = ({ id }) => query =>
|
||||
getMetrics(
|
||||
Object.assign({}, query, {
|
||||
instanceId: id
|
||||
})
|
||||
);
|
||||
|
||||
const addNestedResolvers = instance =>
|
||||
Object.assign({}, instance, {
|
||||
metrics: metricsResolver(instance)
|
||||
});
|
||||
|
||||
return Promise.resolve(
|
||||
instances.filter(find(cleanQuery(query))).map(addNestedResolvers)
|
||||
);
|
||||
};
|
||||
|
||||
const getUnfilteredServices = query => {
|
||||
@ -528,10 +556,6 @@ const config = ({
|
||||
return _plain ? config : Promise.resolve(config);
|
||||
};
|
||||
|
||||
const getMetrics = () => {
|
||||
return Promise.resolve(metricData);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
portal: getPortal,
|
||||
deploymentGroups: getDeploymentGroups,
|
||||
@ -554,6 +578,5 @@ 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,
|
||||
metrics: getMetrics
|
||||
config
|
||||
};
|
||||
|
@ -167,6 +167,23 @@ enum HealthyStatus {
|
||||
UNAVAILABLE
|
||||
}
|
||||
|
||||
type Metric {
|
||||
time: String!
|
||||
value: Float!
|
||||
}
|
||||
|
||||
enum MetricName {
|
||||
AVG_MEM_BYTES
|
||||
AVG_LOAD_PERCENT
|
||||
AGG_NETWORK_BYTES
|
||||
}
|
||||
|
||||
type InstanceMetric {
|
||||
instance: String!
|
||||
name: MetricName!
|
||||
metrics: [Metric]
|
||||
}
|
||||
|
||||
type Instance {
|
||||
id: ID!
|
||||
name: String!
|
||||
@ -175,6 +192,7 @@ type Instance {
|
||||
healthy: HealthyStatus
|
||||
watches: [String]
|
||||
jobs: [String]
|
||||
metrics(names: [MetricName]!, start: String!, end: String!): [InstanceMetric]!
|
||||
}
|
||||
|
||||
type Datacenter {
|
||||
@ -184,24 +202,6 @@ type Datacenter {
|
||||
}
|
||||
|
||||
|
||||
type Metric {
|
||||
time: String!
|
||||
value: Float!
|
||||
}
|
||||
|
||||
enum MetricName {
|
||||
AVG_MEM_BYTES,
|
||||
AVG_LOAD_PERCENT,
|
||||
AGG_NETWORK_BYTES
|
||||
}
|
||||
|
||||
type InstanceMetric {
|
||||
instance: String!
|
||||
name: MetricName!
|
||||
metrics: [Metric]
|
||||
}
|
||||
|
||||
|
||||
# we probably wont use some of these queries or arguments
|
||||
# but this way we expose the entire db through gql
|
||||
type Query {
|
||||
|
Loading…
Reference in New Issue
Block a user