Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display custom metrics for pods if they are available. #1109

Merged
merged 1 commit into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ window.OPENSHIFT_CONSTANTS = {

// true indicates that deployment metrics should be disabled on the web console overview
DISABLE_OVERVIEW_METRICS: false,

// true indicates that custom metrics should be disabled when viewing pod metrics
DISABLE_CUSTOM_METRICS: false,

// true indicates that none of the routers support wildcard subdomains and
// removes the option from the route creation form.
Expand Down
36 changes: 36 additions & 0 deletions app/scripts/directives/podMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,41 @@ angular.module('openshiftConsole')
});
}

if (!window.OPENSHIFT_CONSTANTS.DISABLE_CUSTOM_METRICS) {
// Load any custom metrics onto the page
MetricsService.getCustomMetrics(scope.pod).then(
function(response) {
angular.forEach(response, function(metric) {

// set the label to the description if specified
var label = metric.description || metric.name;

// get the unit value if specified
var unit = metric.unit || "";

scope.metrics.push({
label: label,
units: unit,
chartPrefix: "custom-" + _.uniqueId('custom-metric-'),
chartType: "spline",

datasets: [
{
id: "custom/" + metric.name,
label: label,
type: metric.type,
data: []
},
]
});

});
// update the page with the new charts.
update();
}
);
}

// Set to true when any data has been loaded (or failed to load).
scope.loaded = false;
scope.noData = true;
Expand Down Expand Up @@ -260,6 +295,7 @@ angular.module('openshiftConsole')
var lastPoint;
var config = {
metric: dataset.id,
type: dataset.type,
bucketDuration: getBucketDuration()
};

Expand Down
50 changes: 48 additions & 2 deletions app/scripts/services/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
angular.module("openshiftConsole")
.factory("MetricsService", function($filter, $http, $q, $rootScope, APIDiscovery) {
var POD_GAUGE_TEMPLATE = "/gauges/{containerName}%2F{podUID}%2F{metric}/data";
var POD_COUNTER_TEMPLATE = "/counters/{containerName}%2F{podUID}%2F{metric}/data";

var metricsURL;
function getMetricsURL() {
Expand Down Expand Up @@ -50,7 +51,13 @@ angular.module("openshiftConsole")

function getRequestURL(config) {
return getMetricsURL().then(function(metricsURL) {
var template = metricsURL + POD_GAUGE_TEMPLATE;
var template;
// if no type is specified, it is assumed the metric is a gauge
if (config.type === "counter") {
template = metricsURL + POD_COUNTER_TEMPLATE;
} else {
template = metricsURL + POD_GAUGE_TEMPLATE;
}
return URI.expand(template, {
podUID: config.pod.metadata.uid,
containerName: config.containerName,
Expand Down Expand Up @@ -169,6 +176,44 @@ angular.module("openshiftConsole")
});
};

// Returns custom metrics available for a particular pod
var getCustomMetrics = function(pod) {
var namespace = pod.metadata.namespace;
var podId = pod.metadata.uid;

return getMetricsURL().then(function(metricsURL) {

if (!metricsURL) {
return null;
}

var url = metricsURL + "/metrics";

var params = {
tags: "custom_metric:true,pod_id:" + podId
};

return $http.get(url, {
auth: {},
headers: {
Accept: 'application/json',
'Hawkular-Tenant': namespace
},
params: params
}).then(function(response) {
return _.map(response.data, function(value) {
return {
name: value.tags.metric_name,
unit: value.tags.units,
description: value.tags.description,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra trailing comma

type: value.type
};
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest using _.map. (Untested, but I think this will work.)

return _.map(response.data, function(value) {
  return {
    name: value.tags.metric_name,
    unit: value.tags.units,
    description: value.tags.description
  };
});

});
});
};


return {
// Check if the metrics service is available. The service is considered
// available if a metrics URL is set. Returns a promise resolved with a
Expand Down Expand Up @@ -255,6 +300,7 @@ angular.module("openshiftConsole")
// end: end time in millis (optional)
//
// Returns a promise resolved with the metrics data.
getPodMetrics: getPodMetrics
getPodMetrics: getPodMetrics,
getCustomMetrics: getCustomMetrics,
};
});
70 changes: 57 additions & 13 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ CLI:{
},
DEFAULT_HPA_CPU_TARGET_PERCENT:80,
DISABLE_OVERVIEW_METRICS:!1,
DISABLE_CUSTOM_METRICS:!1,
DISABLE_WILDCARD_ROUTES:!0,
AVAILABLE_KINDS_BLACKLIST:[ "Binding", "Ingress", "DeploymentConfigRollback" ],
ENABLE_TECH_PREVIEW_FEATURE:{
Expand Down Expand Up @@ -2929,15 +2930,15 @@ return a ? a + "/metrics/stats/query" :a;
}
function j(a) {
return f().then(function(b) {
var c = b + n;
return URI.expand(c, {
var c;
return c = "counter" === a.type ? b + o :b + n, URI.expand(c, {
podUID:a.pod.metadata.uid,
containerName:a.containerName,
metric:a.metric
}).toString();
});
}
var k, l, m, n = "/gauges/{containerName}%2F{podUID}%2F{metric}/data", o = function(a) {
var k, l, m, n = "/gauges/{containerName}%2F{podUID}%2F{metric}/data", o = "/counters/{containerName}%2F{podUID}%2F{metric}/data", p = function(a) {
return f().then(function(c) {
return !!c && (!a || (!!l || !m && b.get(c).then(function() {
return l = !0, !0;
Expand All @@ -2948,13 +2949,13 @@ response:a
}), !1;
})));
});
}, p = function(a) {
}, q = function(a) {
var b = a.split("/");
return {
podUID:b[1],
descriptor:b[2] + "/" + b[3]
};
}, q = function(a, c, d) {
}, r = function(a, c, d) {
var e = _.indexBy(d.pods, "metadata.uid");
return b.post(a, c, {
auth:{},
Expand All @@ -2965,40 +2966,65 @@ Accept:"application/json",
}
}).then(function(a) {
var b = {}, c = function(a, c) {
var d = p(c), f = _.get(e, [ d.podUID, "metadata", "name" ]), h = g(a);
var d = q(c), f = _.get(e, [ d.podUID, "metadata", "name" ]), h = g(a);
_.set(b, [ d.descriptor, f ], h);
};
return _.each(a.data.counter, c), _.each(a.data.gauge, c), b;
});
}, r = _.template("descriptor_name:network/tx_rate|network/rx_rate,type:pod,pod_id:<%= uid %>"), s = _.template("descriptor_name:memory/usage|cpu/usage_rate,type:pod_container,pod_id:<%= uid %>,container_name:<%= containerName %>"), t = function(a) {
}, s = _.template("descriptor_name:network/tx_rate|network/rx_rate,type:pod,pod_id:<%= uid %>"), t = _.template("descriptor_name:memory/usage|cpu/usage_rate,type:pod_container,pod_id:<%= uid %>,container_name:<%= containerName %>"), u = function(a) {
return i().then(function(b) {
var d = {
bucketDuration:a.bucketDuration,
start:a.start
};
a.end && (d.end = a.end);
var e = [], f = h(_.map(a.pods, "metadata.uid")), g = _.assign({
tags:s({
tags:t({
uid:f,
containerName:a.containerName
})
}, d);
e.push(q(b, g, a));
e.push(r(b, g, a));
var i = _.assign({
tags:r({
tags:s({
uid:f
})
}, d);
return e.push(q(b, i, a)), c.all(e).then(function(a) {
return e.push(r(b, i, a)), c.all(e).then(function(a) {
var b = {};
return _.each(a, function(a) {
_.assign(b, a);
}), b;
});
});
}, v = function(a) {
var c = a.metadata.namespace, d = a.metadata.uid;
return f().then(function(a) {
if (!a) return null;
var e = a + "/metrics", f = {
tags:"custom_metric:true,pod_id:" + d
};
return b.get(e, {
auth:{},
headers:{
Accept:"application/json",
"Hawkular-Tenant":c
},
params:f
}).then(function(a) {
return _.map(a.data, function(a) {
return {
isAvailable:o,
name:a.tags.metric_name,
unit:a.tags.units,
description:a.tags.description,
type:a.type
};
});
});
});
};
return {
isAvailable:p,
getMetricsURL:f,
get:function(a) {
return j(a).then(function(c) {
Expand Down Expand Up @@ -3044,7 +3070,8 @@ usage:_.head(g(b.data))
});
});
},
getPodMetrics:t
getPodMetrics:u,
getCustomMetrics:v
};
} ]), angular.module("openshiftConsole").factory("MetricsCharts", [ "$timeout", "ConversionService", function(a, b) {
var c = function(a, c) {
Expand Down Expand Up @@ -11264,6 +11291,7 @@ return Math.floor(r() / F) + "ms";
function t(a, b, c) {
var d, e = {
metric:b.id,
type:b.type,
bucketDuration:s()
};
return b.data && b.data.length ? (d = _.last(b.data), e.start = d.end) :e.start = c, m.pod ? _.assign(e, {
Expand Down Expand Up @@ -11382,6 +11410,22 @@ id:"network/rx_rate",
label:"Received",
data:[]
} ]
}), window.OPENSHIFT_CONSTANTS.DISABLE_CUSTOM_METRICS || j.getCustomMetrics(m.pod).then(function(a) {
angular.forEach(a, function(a) {
var b = a.description || a.name, c = a.unit || "";
m.metrics.push({
label:b,
units:c,
chartPrefix:"custom-" + _.uniqueId("custom-metric-"),
chartType:"spline",
datasets:[ {
id:"custom/" + a.name,
label:b,
type:a.type,
data:[]
} ]
});
}), z();
}), m.loaded = !1, m.noData = !0, m.showComputeUnitsHelp = function() {
k.showComputeUnitsHelp();
}, j.getMetricsURL().then(function(a) {
Expand Down