Skip to content

Commit

Permalink
Fix k8s scheduler compatibility issue (elastic#19699)
Browse files Browse the repository at this point in the history
(cherry picked from commit aa60a58)
ChrsMark committed Jul 8, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2223653 commit 1274d99
Showing 10 changed files with 1,451 additions and 148 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
@@ -309,6 +309,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Set tags correctly if the dimension value is ARN {issue}19111[19111] {pull}19433[19433]
- Fix bug incorrect parsing of float numbers as integers in Couchbase module {issue}18949[18949] {pull}19055[19055]
- Add missing info about the rest of the azure metricsets in the documentation. {pull}19601[19601]
- Fix k8s scheduler compatibility issue. {pull}19699[19699]

*Packetbeat*

20 changes: 19 additions & 1 deletion metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
@@ -25842,7 +25842,7 @@ type: long

--

*`kubernetes.scheduler.scheduling.pod.preemption.victims.count`*::
*`kubernetes.scheduler.scheduling.pod.preemption.victims.bucket.*`*::
+
--
Pod preemption victims
@@ -25851,6 +25851,24 @@ type: long

--

*`kubernetes.scheduler.scheduling.pod.preemption.victims.sum`*::
+
--
Pod preemption victims sum

type: long

--

*`kubernetes.scheduler.scheduling.pod.preemption.victims.count`*::
+
--
Pod preemption victims count

type: long

--

*`kubernetes.scheduler.scheduling.pod.attempts.count`*::
+
--
23 changes: 23 additions & 0 deletions metricbeat/helper/prometheus/metric.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
package prometheus

import (
"fmt"
"math"
"strconv"
"strings"
@@ -102,6 +103,14 @@ func OpMultiplyBuckets(multiplier float64) MetricOption {
}
}

// OpSetSuffix extends the field's name with the given suffix if the value of the metric
// is numeric (and not histogram or quantile), otherwise does nothing
func OpSetNumericMetricSuffix(suffix string) MetricOption {
return opSetNumericMetricSuffix{
suffix: suffix,
}
}

// Metric directly maps a Prometheus metric to a Metricbeat field
func Metric(field string, options ...MetricOption) MetricMap {
return &commonMetric{
@@ -378,6 +387,20 @@ func (o opMultiplyBuckets) Process(field string, value interface{}, labels commo
return field, histogram, labels
}

type opSetNumericMetricSuffix struct {
suffix string
}

// Process will extend the field's name with the given suffix
func (o opSetNumericMetricSuffix) Process(field string, value interface{}, labels common.MapStr) (string, interface{}, common.MapStr) {
_, ok := value.(float64)
if !ok {
return field, value, labels
}
field = fmt.Sprintf("%v.%v", field, o.suffix)
return field, value, labels
}

type opUnixTimestampValue struct {
}

2 changes: 1 addition & 1 deletion metricbeat/module/kubernetes/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion metricbeat/module/kubernetes/scheduler/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -112,9 +112,15 @@
- name: e2e.duration.us.count
type: long
description: End to end scheduling count
- name: pod.preemption.victims.count
- name: pod.preemption.victims.bucket.*
type: long
description: Pod preemption victims
- name: pod.preemption.victims.sum
type: long
description: Pod preemption victims sum
- name: pod.preemption.victims.count
type: long
description: Pod preemption victims count
- name: pod.attempts.count
type: long
description: Pod attempts count

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
[
{
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"client": {
"request": {
"count": 25425
}
},
"code": "200",
"host": "localhost:8443",
"method": "GET"
},
"Index": "",
"ID": "",
"Namespace": "",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"process": {
"cpu": {
"sec": 67
},
"fds": {
"open": {
"count": 12
}
},
"memory": {
"resident": {
"bytes": 53444608
},
"virtual": {
"bytes": 148291584
}
},
"started": {
"sec": 1592899682.08
}
},
"scheduling": {
"e2e": {
"duration": {
"us": {
"bucket": {
"+Inf": 10,
"1000": 0,
"1024000": 10,
"128000": 10,
"16000": 8,
"16384000": 10,
"2000": 0,
"2048000": 10,
"256000": 10,
"32000": 10,
"4000": 0,
"4096000": 10,
"512000": 10,
"64000": 10,
"8000": 4,
"8192000": 10
},
"count": 10,
"sum": 104991.73000000001
}
}
},
"pod": {
"preemption": {
"victims": {
"bucket": {
"+Inf": 0,
"10": 0,
"15": 0,
"20": 0,
"25": 0,
"30": 0,
"35": 0,
"40": 0,
"45": 0,
"5": 0,
"50": 0
},
"count": 0,
"sum": 0
}
}
}
}
},
"Index": "",
"ID": "",
"Namespace": "",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"operation": "predicate_evaluation",
"scheduling": {
"duration": {
"seconds": {
"count": 10,
"percentile": {
"50": 0.000060365,
"90": 0.000115423,
"99": 0.000754095
},
"sum": 0.0013853759999999998
}
}
}
},
"Index": "",
"ID": "",
"Namespace": "",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"operation": "binding",
"scheduling": {
"duration": {
"seconds": {
"count": 10,
"percentile": {
"50": 0.008087556,
"90": 0.019238477,
"99": 0.021775325
},
"sum": 0.101037043
}
}
}
},
"Index": "",
"ID": "",
"Namespace": "",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"client": {
"request": {
"count": 1
}
},
"code": "403",
"host": "localhost:8443",
"method": "GET"
},
"Index": "",
"ID": "",
"Namespace": "",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"leader": {
"is_master": true
},
"name": "kube-scheduler"
},
"Index": "",
"ID": "",
"Namespace": "",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"client": {
"request": {
"count": 16634
}
},
"code": "200",
"host": "localhost:8443",
"method": "PUT"
},
"Index": "",
"ID": "",
"Namespace": "",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"client": {
"request": {
"count": 22
}
},
"code": "201",
"host": "localhost:8443",
"method": "POST"
},
"Index": "",
"ID": "",
"Namespace": "",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
}
]
5 changes: 4 additions & 1 deletion metricbeat/module/kubernetes/scheduler/scheduler.go
Original file line number Diff line number Diff line change
@@ -38,7 +38,10 @@ func init() {
"leader_election_master_status": prometheus.BooleanMetric("leader.is_master"),
"scheduler_e2e_scheduling_duration_seconds": prometheus.Metric("scheduling.e2e.duration.us",
prometheus.OpMultiplyBuckets(1000000)),
"scheduler_pod_preemption_victims": prometheus.Metric("scheduling.pod.preemption.victims.count"),
"scheduler_pod_preemption_victims": prometheus.Metric("scheduling.pod.preemption.victims",
// this is needed in order to solve compatibility issue of different
// different k8s versions, issue: https://github.com/elastic/beats/issues/19332
prometheus.OpSetNumericMetricSuffix("count")),
"scheduler_schedule_attempts_total": prometheus.Metric("scheduling.pod.attempts.count"),
"scheduler_scheduling_duration_seconds": prometheus.Metric("scheduling.duration.seconds"),
},
4 changes: 4 additions & 0 deletions metricbeat/module/kubernetes/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
@@ -34,6 +34,10 @@ func TestEventMapping(t *testing.T) {
MetricsFile: "./_meta/test/metrics.scheduler.1.14",
ExpectedFile: "./_meta/test/metrics.scheduler.1.14.expected",
},
{
MetricsFile: "./_meta/test/metrics.scheduler.1.17",
ExpectedFile: "./_meta/test/metrics.scheduler.1.17.expected",
},
},
)
}

0 comments on commit 1274d99

Please sign in to comment.