Skip to content

Commit 617df3f

Browse files
author
OpenShift Bot
authored
Merge pull request #1022 from spadgett/metrics-cpu-cores
Merged by openshift-bot
2 parents 3e63c9c + ed4e563 commit 617df3f

File tree

5 files changed

+49
-32
lines changed

5 files changed

+49
-32
lines changed

Diff for: app/scripts/directives/deploymentMetrics.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ angular.module('openshiftConsole')
6262
chartID: "memory-" + scope.uniqueID
6363
}, {
6464
label: "CPU",
65-
units: "millicores",
65+
units: "cores",
66+
convert: ConversionService.millicoresToCores,
6667
descriptor: 'cpu/usage_rate',
6768
type: 'pod_container',
6869
chartID: "cpu-" + scope.uniqueID

Diff for: app/scripts/directives/podMetrics.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ angular.module('openshiftConsole')
5757
if (_.includes(scope.includedMetrics, "cpu")) {
5858
scope.metrics.push({
5959
label: "CPU",
60-
units: "millicores",
60+
units: "cores",
6161
chartPrefix: "cpu-",
62-
convert: _.round,
62+
convert: ConversionService.millicoresToCores,
63+
// Max number of decimal places to show for usage donut.
64+
usagePrecision: 3,
6365
containerMetric: true,
6466
datasets: [
6567
{
@@ -134,7 +136,12 @@ angular.module('openshiftConsole')
134136

135137
var createSparklineConfig = function(metric) {
136138
var chartID = metric.chartPrefix + scope.uniqueID + '-sparkline';
137-
return MetricsCharts.getDefaultSparklineConfig(chartID, metric.units);
139+
var config = MetricsCharts.getDefaultSparklineConfig(chartID, metric.units);
140+
if (metric.datasets.length === 1) {
141+
_.set(config, 'legend.show', false);
142+
}
143+
144+
return config;
138145
};
139146

140147
function getLimit(metricID) {
@@ -154,8 +161,7 @@ angular.module('openshiftConsole')
154161
case 'cpu/usage_rate':
155162
var cpuLimit = getCPULimit(container);
156163
if (cpuLimit) {
157-
// Convert cores to millicores.
158-
return _.round(usageValueFilter(cpuLimit) * 1000);
164+
return usageValueFilter(cpuLimit);
159165
}
160166
break;
161167
}
@@ -354,9 +360,9 @@ angular.module('openshiftConsole')
354360
currentUsage = metric.convert(currentUsage);
355361
}
356362

357-
dataset.used = _.round(currentUsage);
363+
dataset.used = d3.round(currentUsage, metric.usagePrecision);
358364
if (dataset.total) {
359-
dataset.available = _.round(dataset.total - currentUsage);
365+
dataset.available = d3.round(dataset.total - currentUsage, metric.usagePrecision);
360366
}
361367
metric.totalUsed += dataset.used;
362368
}

Diff for: app/scripts/services/convert.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ angular.module("openshiftConsole")
1515
return value;
1616
}
1717

18-
// Round to one decimal place
1918
return value / 1024;
2019
};
2120

21+
var millicoresToCores = function(value) {
22+
if (!value) {
23+
return value;
24+
}
25+
26+
return value / 1000;
27+
};
28+
2229
return {
2330
bytesToMiB: bytesToMiB,
24-
bytesToKiB: bytesToKiB
31+
bytesToKiB: bytesToKiB,
32+
millicoresToCores: millicoresToCores
2533
};
2634
});

Diff for: app/scripts/services/metricsCharts.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ angular.module("openshiftConsole")
1111
switch (metricID) {
1212
case 'memory/usage':
1313
return _.round(ConversionService.bytesToMiB(point.value), 2);
14+
case 'cpu/usage_rate':
15+
return ConversionService.millicoresToCores(point.value);
1416
case 'network/rx_rate':
1517
case 'network/tx_rate':
1618
return _.round(ConversionService.bytesToKiB(point.value), 2);
@@ -80,11 +82,6 @@ angular.module("openshiftConsole")
8082
left: 0,
8183
top: 20,
8284
bottom: 0
83-
},
84-
tick: {
85-
format: function(value) {
86-
return d3.round(value, 3);
87-
}
8885
}
8986
}
9087
},
@@ -97,7 +94,8 @@ angular.module("openshiftConsole")
9794
tooltip: {
9895
format: {
9996
value: function(value) {
100-
return d3.round(value, 2) + " " + units;
97+
var precision = units === 'cores' ? 3 : 2;
98+
return d3.round(value, precision) + " " + units;
10199
}
102100
},
103101
}
@@ -126,7 +124,7 @@ angular.module("openshiftConsole")
126124
},
127125

128126
formatUsage: function(usage) {
129-
if (usage < 0.01) {
127+
if (usage < 0.001) {
130128
return '0';
131129
}
132130

Diff for: dist/scripts/scripts.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -3051,6 +3051,9 @@ switch (c) {
30513051
case "memory/usage":
30523052
return _.round(b.bytesToMiB(a.value), 2);
30533053

3054+
case "cpu/usage_rate":
3055+
return b.millicoresToCores(a.value);
3056+
30543057
case "network/rx_rate":
30553058
case "network/tx_rate":
30563059
return _.round(b.bytesToKiB(a.value), 2);
@@ -3113,11 +3116,6 @@ padding:{
31133116
left:0,
31143117
top:20,
31153118
bottom:0
3116-
},
3117-
tick:{
3118-
format:function(a) {
3119-
return d3.round(a, 3);
3120-
}
31213119
}
31223120
}
31233121
},
@@ -3130,7 +3128,8 @@ height:c ? 35 :175
31303128
tooltip:{
31313129
format:{
31323130
value:function(a) {
3133-
return d3.round(a, 2) + " " + b;
3131+
var c = "cores" === b ? 3 :2;
3132+
return d3.round(a, c) + " " + b;
31343133
}
31353134
}
31363135
}
@@ -3150,7 +3149,7 @@ b.push(a.start), f[d].push(e);
31503149
}), e.columns = [ b ].concat(_.values(f)), e;
31513150
},
31523151
formatUsage:function(a) {
3153-
return a < .01 ? "0" :a < 1 ? d3.format(".1r")(a) :d3.format(".2r")(a);
3152+
return a < .001 ? "0" :a < 1 ? d3.format(".1r")(a) :d3.format(".2r")(a);
31543153
},
31553154
redraw:function(b) {
31563155
a(function() {
@@ -3777,10 +3776,13 @@ var a = function(a) {
37773776
return a ? a / 1048576 :a;
37783777
}, b = function(a) {
37793778
return a ? a / 1024 :a;
3779+
}, c = function(a) {
3780+
return a ? a / 1e3 :a;
37803781
};
37813782
return {
37823783
bytesToMiB:a,
3783-
bytesToKiB:b
3784+
bytesToKiB:b,
3785+
millicoresToCores:c
37843786
};
37853787
}), angular.module("openshiftConsole").service("BreadcrumbsService", [ "$filter", "APIService", "Navigate", function(a, b, c) {
37863788
var d = a("annotation"), e = a("displayName"), f = function(a) {
@@ -11102,7 +11104,7 @@ break;
1110211104

1110311105
case "cpu/usage_rate":
1110411106
var d = D(b);
11105-
if (d) return _.round(1e3 * k(d));
11107+
if (d) return k(d);
1110611108
}
1110711109
return null;
1110811110
}
@@ -11192,7 +11194,7 @@ return !(l.metricsError || J > 1) && (l.pod && _.get(l, "options.selectedContain
1119211194
function w(a, b, c) {
1119311195
b.total = m(b.id), b.total && (l.hasLimits = !0);
1119411196
var d = _.get(c, "usage.value");
11195-
isNaN(d) && (d = 0), a.convert && (d = a.convert(d)), b.used = _.round(d), b.total && (b.available = _.round(b.total - d)), a.totalUsed += b.used;
11197+
isNaN(d) && (d = 0), a.convert && (d = a.convert(d)), b.used = d3.round(d, a.usagePrecision), b.total && (b.available = d3.round(b.total - d, a.usagePrecision)), a.totalUsed += b.used;
1119611198
}
1119711199
function x(a, b) {
1119811200
l.noData = !1;
@@ -11244,9 +11246,10 @@ data:[]
1124411246
} ]
1124511247
}), _.includes(l.includedMetrics, "cpu") && l.metrics.push({
1124611248
label:"CPU",
11247-
units:"millicores",
11249+
units:"cores",
1124811250
chartPrefix:"cpu-",
11249-
convert:_.round,
11251+
convert:h.millicoresToCores,
11252+
usagePrecision:3,
1125011253
containerMetric:!0,
1125111254
datasets:[ {
1125211255
id:"cpu/usage_rate",
@@ -11295,8 +11298,8 @@ widht:175
1129511298
}
1129611299
};
1129711300
}, I = function(a) {
11298-
var b = a.chartPrefix + l.uniqueID + "-sparkline";
11299-
return i.getDefaultSparklineConfig(b, a.units);
11301+
var b = a.chartPrefix + l.uniqueID + "-sparkline", c = i.getDefaultSparklineConfig(b, a.units);
11302+
return 1 === a.datasets.length && _.set(c, "legend.show", !1), c;
1130011303
}, J = 0;
1130111304
l.$watch("options", function() {
1130211305
_.each(l.metrics, function(a) {
@@ -11453,7 +11456,8 @@ type:"pod_container",
1145311456
chartID:"memory-" + b.uniqueID
1145411457
}, {
1145511458
label:"CPU",
11456-
units:"millicores",
11459+
units:"cores",
11460+
convert:g.millicoresToCores,
1145711461
descriptor:"cpu/usage_rate",
1145811462
type:"pod_container",
1145911463
chartID:"cpu-" + b.uniqueID

0 commit comments

Comments
 (0)