BigW Consortium Gitlab

Commit 8c66ced7 by Phil Hughes

Added deployment data to metrics graphs

Closes #26914
parent 5e2219db
import d3 from 'd3';
export default class Deployments {
constructor(width) {
this.width = width;
this.timeFormat = d3.time.format('%b %d, %Y, %H:%M%p');
}
init(chartData) {
this.chartData = chartData;
this.x = d3.time.scale().range([0, this.width]);
this.x.domain(d3.extent(this.chartData, d => d.time));
this.getData();
}
getData() {
$.ajax({
url: 'http://192.168.0.2:3000/root/hello-world/environments/21/deployments',
dataType: 'JSON',
})
.done((data) => {
this.data = [];
data.deployments.forEach((deployment) => {
const date = new Date(deployment.created_at);
if (this.x(date) >= 0) {
this.data.push({
id: deployment.id,
time: new Date(deployment.created_at),
sha: deployment.sha,
});
}
});
this.plotData();
});
}
plotData() {
const charts = d3.selectAll('.prometheus-graph .graph-container');
charts
.each((d, i) => {
const chart = d3.select(charts[0][i]);
this.createLine(chart);
this.createDeployInfoBox(chart);
});
}
createLine(chart) {
chart.append('g')
.attr('class', 'deploy-info')
.selectAll('.deploy-info')
.data(this.data)
.enter()
.append('g')
.attr('class', d => `deploy-info-${d.id}`)
.attr('transform', d => `translate(${Math.floor(this.x(d.time)) + 1}, -1)`)
.append('line')
.attr('class', 'deployment-line')
.attr('stroke', '#000000')
.attr('stroke-width', '2')
.attr({
x1: 0,
x2: 0,
y1: 0,
y2: chart.node().getBoundingClientRect().height - 22,
});
}
createDeployInfoBox(chart) {
this.data.forEach((d) => {
const group = chart.select(`.deploy-info-${d.id}`)
.append('svg')
.attr('class', 'rect-text-metric deploy-info-rect')
.attr('x', '5')
.attr('y', '0')
.attr('width', 100)
.attr('height', 35);
group.append('rect')
.attr('class', 'rect-metric')
.attr('x', 0)
.attr('y', 0)
.attr('rx', 3)
.attr('width', '100%')
.attr('height', '100%')
const text = group.append('text')
.attr('x', 5)
.attr('y', '50%')
.attr('style', 'dominant-baseline: middle;')
.text((d) => {
return `${d.sha.slice(0, 6)} - ${this.timeFormat(d.time)}`;
});
group.attr('width', Math.floor(text.node().getBoundingClientRect().width) + 10);
});
}
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import d3 from 'd3'; import d3 from 'd3';
import statusCodes from '~/lib/utils/http_status'; import statusCodes from '~/lib/utils/http_status';
import Deployments from './deployments';
import '../lib/utils/common_utils'; import '../lib/utils/common_utils';
import '../flash'; import '../flash';
...@@ -25,6 +26,8 @@ class PrometheusGraph { ...@@ -25,6 +26,8 @@ class PrometheusGraph {
this.width = parentContainerWidth - this.margin.left - this.margin.right; this.width = parentContainerWidth - this.margin.left - this.margin.right;
this.height = 400 - this.margin.top - this.margin.bottom; this.height = 400 - this.margin.top - this.margin.bottom;
this.backOffRequestCounter = 0; this.backOffRequestCounter = 0;
this.deployments = new Deployments(this.width);
this.configureGraph(); this.configureGraph();
this.init(); this.init();
} }
...@@ -45,6 +48,7 @@ class PrometheusGraph { ...@@ -45,6 +48,7 @@ class PrometheusGraph {
} else { } else {
this.transformData(metricsResponse); this.transformData(metricsResponse);
this.createGraph(); this.createGraph();
this.deployments.init(this.data[Object.keys(this.data)[0]]);
} }
}); });
} }
...@@ -64,6 +68,7 @@ class PrometheusGraph { ...@@ -64,6 +68,7 @@ class PrometheusGraph {
.attr('width', this.width + this.margin.left + this.margin.right) .attr('width', this.width + this.margin.left + this.margin.right)
.attr('height', this.height + this.margin.bottom + this.margin.top) .attr('height', this.height + this.margin.bottom + this.margin.top)
.append('g') .append('g')
.attr('class', 'graph-container')
.attr('transform', `translate(${this.margin.left},${this.margin.top})`); .attr('transform', `translate(${this.margin.left},${this.margin.top})`);
const axisLabelContainer = d3.select(prometheusGraphContainer) const axisLabelContainer = d3.select(prometheusGraphContainer)
...@@ -204,14 +209,13 @@ class PrometheusGraph { ...@@ -204,14 +209,13 @@ class PrometheusGraph {
const d0 = valuesToPlot[timeValueIndex - 1]; const d0 = valuesToPlot[timeValueIndex - 1];
const d1 = valuesToPlot[timeValueIndex]; const d1 = valuesToPlot[timeValueIndex];
const currentData = timeValueFromOverlay - d0.time > d1.time - timeValueFromOverlay ? d1 : d0; const currentData = timeValueFromOverlay - d0.time > d1.time - timeValueFromOverlay ? d1 : d0;
const maxValueMetric = y(d3.max(valuesToPlot.map(metricValue => metricValue.value))); const maxValueMetric = Math.floor(y(d3.max(valuesToPlot.map(metricValue => metricValue.value))));
const currentTimeCoordinate = x(currentData.time); const currentTimeCoordinate = Math.floor(x(currentData.time));
const graphSpecifics = this.graphSpecificProperties[key]; const graphSpecifics = this.graphSpecificProperties[key];
// Remove the current selectors // Remove the current selectors
d3.selectAll(`${prometheusGraphContainer} .selected-metric-line`).remove(); d3.selectAll(`${prometheusGraphContainer} .selected-metric-line`).remove();
d3.selectAll(`${prometheusGraphContainer} .circle-metric`).remove(); d3.selectAll(`${prometheusGraphContainer} .circle-metric`).remove();
d3.selectAll(`${prometheusGraphContainer} .rect-text-metric`).remove(); d3.selectAll(`${prometheusGraphContainer} .rect-text-metric:not(.deploy-info-rect)`).remove();
d3.selectAll(`${prometheusGraphContainer} .text-metric`).remove();
chart.append('line') chart.append('line')
.attr('class', 'selected-metric-line') .attr('class', 'selected-metric-line')
...@@ -230,27 +234,28 @@ class PrometheusGraph { ...@@ -230,27 +234,28 @@ class PrometheusGraph {
.attr('r', this.commonGraphProperties.circle_radius_metric); .attr('r', this.commonGraphProperties.circle_radius_metric);
// The little box with text // The little box with text
const rectTextMetric = chart.append('g') const rectTextMetric = chart.append('svg')
.attr('class', 'rect-text-metric') .attr('class', 'rect-text-metric')
.attr('translate', `(${currentTimeCoordinate}, ${y(currentData.value)})`); .attr('x', currentTimeCoordinate)
.attr('y', -1);
rectTextMetric.append('rect') rectTextMetric.append('rect')
.attr('class', 'rect-metric') .attr('class', 'rect-metric')
.attr('x', currentTimeCoordinate + 10) .attr('x', 10)
.attr('y', maxValueMetric) .attr('y', 0)
.attr('width', this.commonGraphProperties.rect_text_width) .attr('width', this.commonGraphProperties.rect_text_width)
.attr('height', this.commonGraphProperties.rect_text_height); .attr('height', this.commonGraphProperties.rect_text_height);
rectTextMetric.append('text') rectTextMetric.append('text')
.attr('class', 'text-metric') .attr('class', 'text-metric')
.attr('x', currentTimeCoordinate + 35) .attr('x', 35)
.attr('y', maxValueMetric + 35) .attr('y', 35)
.text(timeFormat(currentData.time)); .text(timeFormat(currentData.time));
rectTextMetric.append('text') rectTextMetric.append('text')
.attr('class', 'text-metric-date') .attr('class', 'text-metric-date')
.attr('x', currentTimeCoordinate + 15) .attr('x', 15)
.attr('y', maxValueMetric + 15) .attr('y', 15)
.text(dayFormat(currentData.time)); .text(dayFormat(currentData.time));
// Update the text // Update the text
......
...@@ -157,7 +157,8 @@ ...@@ -157,7 +157,8 @@
.prometheus-graph { .prometheus-graph {
text { text {
fill: $stat-graph-axis-fill; fill: #525252;
stroke-width: 0;
} }
} }
...@@ -200,22 +201,15 @@ ...@@ -200,22 +201,15 @@
.rect-text-metric { .rect-text-metric {
fill: $white-light; fill: $white-light;
stroke-width: 1; stroke-width: 1;
stroke: $black; stroke: #e1e1e1;
} }
.rect-axis-text { .rect-axis-text {
fill: $white-light; fill: $white-light;
} }
.text-metric, .text-metric {
.text-median-metric, font-weight: 600;
.text-metric-usage,
.text-metric-date {
fill: $black;
}
.text-metric-date {
font-weight: 200;
} }
.selected-metric-line { .selected-metric-line {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment