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

[8.4](backport #33032) Add enricher to storageclass metricset #33054

Merged
merged 5 commits into from
Sep 13, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]

- Fix and improve AWS metric period calculation to avoid zero-length intervals {pull}32724[32724]
- Add missing cluster metadata to k8s module metricsets {pull}32979[32979]
- Add missing cluster metadata to k8s module metricsets {pull}32979[32979] {pull}33032[33032]

*Packetbeat*

Expand Down
8 changes: 4 additions & 4 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9414,11 +9414,11 @@ SOFTWARE.

--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-autodiscover
Version: v0.2.1
Version: v0.3.0
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.2.1/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.3.0/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down Expand Up @@ -9858,11 +9858,11 @@ SOFTWARE

--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-libs
Version: v0.2.9
Version: v0.2.11
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].9/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].11/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
7 changes: 7 additions & 0 deletions deploy/kubernetes/metricbeat-kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ data:
- state_resourcequota
- state_statefulset
- state_service
- state_persistentvolume
- state_persistentvolumeclaim
- state_storageclass
# If `https` is used to access `kube-state-metrics`, uncomment following settings:
# bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
# ssl.certificate_authorities:
Expand Down Expand Up @@ -303,6 +306,10 @@ rules:
- jobs
- cronjobs
verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources:
- storageclasses
verbs: ["get", "list", "watch"]
- apiGroups:
- ""
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ data:
- state_resourcequota
- state_statefulset
- state_service
- state_persistentvolume
- state_persistentvolumeclaim
- state_storageclass
# If `https` is used to access `kube-state-metrics`, uncomment following settings:
# bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
# ssl.certificate_authorities:
Expand Down
4 changes: 4 additions & 0 deletions deploy/kubernetes/metricbeat/metricbeat-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ rules:
- jobs
- cronjobs
verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources:
- storageclasses
verbs: ["get", "list", "watch"]
- apiGroups:
- ""
resources:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ require (
github.com/aws/smithy-go v1.12.0
github.com/awslabs/kinesis-aggregation/go/v2 v2.0.0-20220623125934-28468a6701b5
github.com/elastic/bayeux v1.0.5
github.com/elastic/elastic-agent-autodiscover v0.2.1
github.com/elastic/elastic-agent-libs v0.2.9
github.com/elastic/elastic-agent-autodiscover v0.3.0
github.com/elastic/elastic-agent-libs v0.2.11
github.com/elastic/elastic-agent-shipper-client v0.2.0
github.com/elastic/elastic-agent-system-metrics v0.4.4
github.com/elastic/go-elasticsearch/v8 v8.2.0
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -593,15 +593,14 @@ github.com/elastic/bayeux v1.0.5 h1:UceFq01ipmT3S8DzFK+uVAkbCdiPR0Bqei8qIGmUeY0=
github.com/elastic/bayeux v1.0.5/go.mod h1:CSI4iP7qeo5MMlkznGvYKftp8M7qqP/3nzmVZoXHY68=
github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqrj3lotWinO9+jFmeDXIC4gvIQs=
github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY=
github.com/elastic/elastic-agent-autodiscover v0.2.1 h1:Nbeayh3vq2FNm6xaFo34mhUdOu0EVlpj53CqCsbU0E4=
github.com/elastic/elastic-agent-autodiscover v0.2.1/go.mod h1:gPnzzfdYNdgznAb+iG9eyyXaQXBbAMHa+Y6Z8hXfcGY=
github.com/elastic/elastic-agent-autodiscover v0.3.0 h1:kdpNnIDnVk7gvQxxR6PzZY7aM8LyMTRkwI/p+FNS17s=
github.com/elastic/elastic-agent-autodiscover v0.3.0/go.mod h1:p3MSf9813JEnolCTD0GyVAr3+Eptg2zQ9aZVFjl4tJ4=
github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6 h1:nFvXHBjYK3e9+xF0WKDeAKK4aOO51uC28s+L9rBmilo=
github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6/go.mod h1:uh/Gj9a0XEbYoM4NYz4LvaBVARz3QXLmlNjsrKY9fTc=
github.com/elastic/elastic-agent-libs v0.2.2/go.mod h1:1xDLBhIqBIjhJ7lr2s+xRFFkQHpitSp8q2zzv1Dqg+s=
github.com/elastic/elastic-agent-libs v0.2.5/go.mod h1:chO3rtcLyGlKi9S0iGVZhYCzDfdDsAQYBc+ui588AFE=
github.com/elastic/elastic-agent-libs v0.2.7/go.mod h1:chO3rtcLyGlKi9S0iGVZhYCzDfdDsAQYBc+ui588AFE=
github.com/elastic/elastic-agent-libs v0.2.9 h1:7jOCqNqEWG0kJb3fa8/SC6beSiys1TmAylH9+hWTnrM=
github.com/elastic/elastic-agent-libs v0.2.9/go.mod h1:chO3rtcLyGlKi9S0iGVZhYCzDfdDsAQYBc+ui588AFE=
github.com/elastic/elastic-agent-libs v0.2.11 h1:ZeYn35Kxt+IdtMPmE01TaDeaahCg/z7MkGPVWUo6Lp4=
github.com/elastic/elastic-agent-libs v0.2.11/go.mod h1:chO3rtcLyGlKi9S0iGVZhYCzDfdDsAQYBc+ui588AFE=
github.com/elastic/elastic-agent-shipper-client v0.2.0 h1:p+5ep48YCOe+3nICeWmiLwQV11yDLad2n4NunI66Shg=
github.com/elastic/elastic-agent-shipper-client v0.2.0/go.mod h1:OyI2W+Mv3JxlkEF3OeT7K0dbuxvwew8ke2Cf4HpLa9Q=
github.com/elastic/elastic-agent-system-metrics v0.4.4 h1:Br3S+TlBhijrLysOvbHscFhgQ00X/trDT5VEnOau0E0=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ data:
- state_resourcequota
- state_statefulset
- state_service
- state_persistentvolume
- state_persistentvolumeclaim
- state_storageclass
- module: kubernetes
metricsets:
- apiserver
Expand Down Expand Up @@ -293,6 +296,10 @@ rules:
- jobs
- cronjobs
verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources:
- storageclasses
verbs: ["get", "list", "watch"]
- apiGroups:
- ""
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ kube_storageclass_created{storageclass="test_storageclass"} 1.501569018e+09
# HELP kube_storageclass_labels Kubernetes labels converted to Prometheus labels.
# TYPE kube_storageclass_labels gauge
kube_storageclass_labels{storageclass="test_storageclass",label_foo="bar"} 1


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"RootFields": {},
"RootFields": null,
"ModuleFields": {
"labels": {
"foo": "bar"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"RootFields": {},
"RootFields": null,
"ModuleFields": {
"labels": {
"addonmanager_kubernetes_io_mode": "EnsureExists"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[
{
"RootFields": {},
"RootFields": null,
"ModuleFields": null,
"MetricSetFields": {
"created": "2021-08-12T14:24:52.000Z",
"name": "standard",
"provisioner": "rancher.io/local-path"
"provisioner": "rancher.io/local-path",
"reclaim_policy": "Delete",
"volume_binding_mode": "WaitForFirstConsumer"
},
"Index": "",
"ID": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
p "github.com/elastic/beats/v7/metricbeat/helper/prometheus"
"github.com/elastic/beats/v7/metricbeat/mb"
k8smod "github.com/elastic/beats/v7/metricbeat/module/kubernetes"
"github.com/elastic/beats/v7/metricbeat/module/kubernetes/util"
"github.com/elastic/elastic-agent-autodiscover/kubernetes"
)

func init() {
Expand All @@ -38,6 +40,7 @@ type StorageClassMetricSet struct {
prometheus p.Prometheus
mapping *p.MetricsMapping
mod k8smod.Module
enricher util.Enricher
}

// NewStorageClassMetricSet returns a prometheus based metricset for Storage classes
Expand All @@ -54,6 +57,7 @@ func NewStorageClassMetricSet(base mb.BaseMetricSet) (mb.MetricSet, error) {
BaseMetricSet: base,
prometheus: prometheus,
mod: mod,
enricher: util.NewResourceMetadataEnricher(base, &kubernetes.StorageClass{}, mod.GetMetricsRepo(), false),
mapping: &p.MetricsMapping{
Metrics: map[string]p.MetricMap{
"kube_storageclass_info": p.InfoMetric(),
Expand All @@ -66,10 +70,12 @@ func NewStorageClassMetricSet(base mb.BaseMetricSet) (mb.MetricSet, error) {
"kube_storageclass_created": p.Metric("created", p.OpUnixTimestampValue()),
},
Labels: map[string]p.LabelMap{
"storageclass": p.KeyLabel("name"),
"provisioner": p.Label("provisioner"),
"reclaimPolicy": p.Label("reclaim_policy"),
"volumeBindingMode": p.Label("volume_binding_mode"),
"storageclass": p.KeyLabel("name"),
"provisioner": p.Label("provisioner"),
"reclaimPolicy": p.Label("reclaim_policy"),
"reclaim_policy": p.Label("reclaim_policy"),
"volumeBindingMode": p.Label("volume_binding_mode"),
"volume_binding_mode": p.Label("volume_binding_mode"),
},
},
}, nil
Expand All @@ -78,6 +84,8 @@ func NewStorageClassMetricSet(base mb.BaseMetricSet) (mb.MetricSet, error) {
// Fetch prometheus metrics and treats those prefixed by mb.ModuleDataKey as
// module rooted fields at the event that gets reported
func (m *StorageClassMetricSet) Fetch(reporter mb.ReporterV2) {
m.enricher.Start()

families, err := m.mod.GetStateMetricsFamilies(m.prometheus)
if err != nil {
m.Logger().Error(err)
Expand All @@ -91,12 +99,24 @@ func (m *StorageClassMetricSet) Fetch(reporter mb.ReporterV2) {
return
}

m.enricher.Enrich(events)

for _, event := range events {
event[mb.NamespaceKey] = "storageclass"
reported := reporter.Event(mb.TransformMapStrToEvent("kubernetes", event, nil))
if !reported {

e, err := util.CreateEvent(event, "kubernetes.storageclass")
if err != nil {
m.Logger().Error(err)
}

if reported := reporter.Event(e); !reported {
m.Logger().Debug("error trying to emit event")
return
}
}
}

// Close stops this metricset
func (m *StorageClassMetricSet) Close() error {
m.enricher.Stop()
return nil
}
2 changes: 2 additions & 0 deletions metricbeat/module/kubernetes/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ func NewResourceMetadataEnricher(
m[id] = metaGen.Generate("persistentvolume", r)
case *kubernetes.PersistentVolumeClaim:
m[id] = metaGen.Generate("persistentvolumeclaim", r)
case *kubernetes.StorageClass:
m[id] = metaGen.Generate("storageclass", r)
default:
m[id] = metaGen.Generate(r.GetObjectKind().GroupVersionKind().Kind, r)
}
Expand Down