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

[Metricbeat][Kubernetes] Extend state_node with more conditions #23905

Merged
merged 3 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- kubernetes.container.cpu.limit.cores and kubernetes.container.cpu.requests.cores are now floats. {issue}11975[11975]
- Change types of numeric metrics from Kubelet summary api to double so as to cover big numbers. {pull}23335[23335]
- Add container.image.name and containe.name ECS fields for state_container. {pull}23802[23802]
- Add support for the MemoryPressure, DiskPressure, OutOfDisk and PIDPressure status conditions in state_node. {pull}[23905]

*Packetbeat*

Expand Down
59 changes: 49 additions & 10 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29807,6 +29807,46 @@ type: keyword
Node unschedulable status


type: boolean

--

*`kubernetes.node.status.memory_pressure`*::
+
--
Node MemoryPressure status


type: boolean

--

*`kubernetes.node.status.disk_pressure`*::
+
--
Node DiskPressure status


type: boolean

--

*`kubernetes.node.status.out_of_disk`*::
+
--
Node OutOfDisk status


type: boolean

--

*`kubernetes.node.status.pid_pressure`*::
+
--
Node PIDPressure status


type: boolean

--
Expand Down Expand Up @@ -30774,7 +30814,7 @@ type: long
*`linux.conntrack.summary.insert_failed`*::
+
--
Number of entries where list insert insert failed
Number of entries where list insert insert failed


type: long
Expand Down Expand Up @@ -40402,7 +40442,7 @@ format: bytes
*`redis.info.memory.used.lua`*::
+
--
Used memory by the Lua engine.
Used memory by the Lua engine.


type: long
Expand All @@ -40414,7 +40454,7 @@ format: bytes
*`redis.info.memory.used.dataset`*::
+
--
The size in bytes of the dataset
The size in bytes of the dataset


type: long
Expand Down Expand Up @@ -40659,7 +40699,7 @@ format: duration
*`redis.info.persistence.rdb.copy_on_write.last_size`*::
+
--
The size in bytes of copy-on-write allocations during the last RBD save operation
The size in bytes of copy-on-write allocations during the last RBD save operation


type: long
Expand Down Expand Up @@ -40788,7 +40828,7 @@ format: bytes
*`redis.info.persistence.aof.size.current`*::
+
--
AOF current file size
AOF current file size


type: long
Expand Down Expand Up @@ -40894,7 +40934,7 @@ format: bytes
*`redis.info.replication.backlog.first_byte_offset`*::
+
--
The master offset of the replication backlog buffer
The master offset of the replication backlog buffer


type: long
Expand Down Expand Up @@ -44559,7 +44599,7 @@ type: keyword
*`system.raid.sync_action`*::
+
--
Current sync action, if the RAID array is redundant
Current sync action, if the RAID array is redundant


type: keyword
Expand Down Expand Up @@ -45000,7 +45040,7 @@ All TCP connections
*`system.socket.summary.tcp.memory`*::
+
--
Memory used by TCP sockets in bytes, based on number of allocated pages and system page size. Corresponds to limits set in /proc/sys/net/ipv4/tcp_mem. Only available on Linux.
Memory used by TCP sockets in bytes, based on number of allocated pages and system page size. Corresponds to limits set in /proc/sys/net/ipv4/tcp_mem. Only available on Linux.


type: integer
Expand Down Expand Up @@ -45146,7 +45186,7 @@ All UDP connections
*`system.socket.summary.udp.memory`*::
+
--
Memory used by UDP sockets in bytes, based on number of allocated pages and system page size. Corresponds to limits set in /proc/sys/net/ipv4/udp_mem. Only available on Linux.
Memory used by UDP sockets in bytes, based on number of allocated pages and system page size. Corresponds to limits set in /proc/sys/net/ipv4/udp_mem. Only available on Linux.


type: integer
Expand Down Expand Up @@ -46837,4 +46877,3 @@ Epoch value of the Zookeeper transaction ID. An epoch signifies the period in wh
type: long

--

29 changes: 17 additions & 12 deletions metricbeat/helper/prometheus/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ type MetricOption interface {
Process(field string, value interface{}, labels common.MapStr) (string, interface{}, common.MapStr)
}

// OpFilter only processes metrics matching the given filter
func OpFilter(filter map[string]string) MetricOption {
return opFilter{
labels: filter,
// OpFilterMap only processes metrics matching the given filter
func OpFilterMap(label string, filterMap map[string]string) MetricOption {
return opFilterMap{
label: label,
filterMap: filterMap,
}
}

Expand Down Expand Up @@ -331,18 +332,22 @@ func (m *infoMetric) GetField() string {
return ""
}

type opFilter struct {
labels map[string]string
type opFilterMap struct {
label string
filterMap map[string]string
}

// Process will return nil if labels don't match the filter
func (o opFilter) Process(field string, value interface{}, labels common.MapStr) (string, interface{}, common.MapStr) {
for k, v := range o.labels {
if labels[k] != v {
return "", nil, nil
// Called by the Prometheus helper to apply extra options on retrieved metrics
// Check whether the value of the specified label is allowed and, if yes, return the metric via the specified mapped field
// Else, if the specified label does not match the filter, return nil
// This is useful in cases where multiple Metricbeat fields need to be defined per Prometheus metric, based on label values
func (o opFilterMap) Process(field string, value interface{}, labels common.MapStr) (string, interface{}, common.MapStr) {
for k, v := range o.filterMap {
if labels[o.label] == k {
return fmt.Sprintf("%v.%v", field, v), value, labels
}
}
return field, value, labels
return "", nil, nil
}

type opLowercaseValue struct{}
Expand Down
33 changes: 30 additions & 3 deletions metricbeat/helper/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,36 @@ func TestPrometheus(t *testing.T) {
msg: "Label metrics, filter",
mapping: &MetricsMapping{
Metrics: map[string]MetricMap{
"first_metric": LabelMetric("first.metric", "label4", OpLowercaseValue(), OpFilter(map[string]string{
"foo": "filtered",
})),
"first_metric": LabelMetric("first.metric", "label4", OpFilterMap(
"label1",
map[string]string{"value1": "foo"},
)),
},
Labels: map[string]LabelMap{
"label1": Label("labels.label1"),
},
},
expected: []common.MapStr{
common.MapStr{
"first": common.MapStr{
"metric": common.MapStr{
"foo": "FOO",
},
},
"labels": common.MapStr{
"label1": "value1",
},
},
},
},
{
msg: "Label metrics, filter",
mapping: &MetricsMapping{
Metrics: map[string]MetricMap{
"first_metric": LabelMetric("first.metric", "label4", OpLowercaseValue(), OpFilterMap(
"foo",
map[string]string{"Filtered": "filtered"},
)),
},
Labels: map[string]LabelMap{
"label1": Label("labels.label1"),
Expand Down
Loading