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 kube-state-metrics service #14794

Merged
merged 21 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c660744
start working on ksm service
odacremolbap Nov 25, 2019
551fe8e
add ksm service
odacremolbap Nov 26, 2019
2dd1100
add ingress fields
odacremolbap Nov 26, 2019
86257cb
fix date format
odacremolbap Nov 27, 2019
c7df6b6
add docs changes
odacremolbap Nov 27, 2019
c13e6c0
Merge branch 'master' of github.com:elastic/beats into task/ksm-service
Nov 28, 2019
3fbd2c8
x-pack reference update
odacremolbap Nov 28, 2019
f9f724c
Merge branch 'master' into task/ksm-service
odacremolbap Nov 28, 2019
e521679
Merge branch 'master' of github.com:elastic/beats into task/ksm-service
Nov 28, 2019
451f197
Merge branch 'task/ksm-service' of github.com:odacremolbap/beats into…
Nov 28, 2019
b40cf2e
Merge branch 'master' of github.com:elastic/beats into task/ksm-service
Nov 29, 2019
9070ba1
Merge branch 'master' of github.com:elastic/beats into task/ksm-service
Nov 29, 2019
f339b04
replace ga with experimental
odacremolbap Nov 29, 2019
fd88608
Merge branch 'master' into task/ksm-service
odacremolbap Dec 5, 2019
59ecbb5
remove non needed if block
odacremolbap Dec 5, 2019
b77e363
remove blank line
odacremolbap Dec 5, 2019
4239c8f
Update metricbeat/module/kubernetes/state_service/README.md
odacremolbap Dec 5, 2019
4c51e21
add description + example to new configuration options at prometheus …
odacremolbap Dec 5, 2019
465482e
Merge branch 'task/ksm-service' of github.com:odacremolbap/beats into…
odacremolbap Dec 5, 2019
0f74b36
I would say this looks a bit better
odacremolbap Dec 5, 2019
91f30d2
Merge branch 'master' into task/ksm-service
odacremolbap Dec 10, 2019
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 @@ -535,6 +535,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Release kubernetes modules `controllermanager`, `scheduler`, `proxy`, `state_cronjob` and `state_resourcequota` as GA. {pull}14584[14584]
- Add module for ActiveMQ. {pull}14580[14580]
- Enable script processor. {pull}14711[14711]
- Add `kube-state-metrics` `state_service` metrics for kubernetes module. {pull}14794[14794]

*Packetbeat*

Expand Down
97 changes: 97 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19456,6 +19456,103 @@ type: keyword

--

[float]
=== service

kubernetes service metrics



*`kubernetes.service.name`*::
+
--
Service name.

type: keyword

--

*`kubernetes.service.cluster_ip`*::
+
--
Internal IP for the service.

type: ip

--

*`kubernetes.service.external_name`*::
+
--
Service external DNS name

type: keyword

--

*`kubernetes.service.external_ip`*::
+
--
Service external IP

type: keyword

--

*`kubernetes.service.load_balancer_ip`*::
+
--
Load Balancer service IP

type: keyword

--

*`kubernetes.service.type`*::
+
--
Service type

type: keyword

--

*`kubernetes.service.ingress_ip`*::
+
--
Ingress IP

type: keyword

--

*`kubernetes.service.ingress_hostname`*::
+
--
Ingress Hostname

type: ip

--

*`kubernetes.service.labels.*`*::
+
--
Labels for service

type: object

--

*`kubernetes.service.created`*::
+
--
Service creation date

type: date

--

[float]
=== statefulset

Expand Down
5 changes: 5 additions & 0 deletions metricbeat/docs/modules/kubernetes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ metricbeat.modules:
- state_container
- state_cronjob
- state_resourcequota
- state_service
period: 10s
hosts: ["kube-state-metrics:8080"]

Expand Down Expand Up @@ -186,6 +187,8 @@ The following metricsets are available:

* <<metricbeat-metricset-kubernetes-state_resourcequota,state_resourcequota>>

* <<metricbeat-metricset-kubernetes-state_service,state_service>>

* <<metricbeat-metricset-kubernetes-state_statefulset,state_statefulset>>

* <<metricbeat-metricset-kubernetes-system,system>>
Expand Down Expand Up @@ -222,6 +225,8 @@ include::kubernetes/state_replicaset.asciidoc[]

include::kubernetes/state_resourcequota.asciidoc[]

include::kubernetes/state_service.asciidoc[]

include::kubernetes/state_statefulset.asciidoc[]

include::kubernetes/system.asciidoc[]
Expand Down
23 changes: 23 additions & 0 deletions metricbeat/docs/modules/kubernetes/state_service.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
////
This file is generated! See scripts/mage/docs_collector.go
////

[[metricbeat-metricset-kubernetes-state_service]]
=== Kubernetes state_service metricset

experimental[]

include::../../../module/kubernetes/state_service/_meta/docs.asciidoc[]


==== Fields

For a description of each field in the metricset, see the
<<exported-fields-kubernetes,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/kubernetes/state_service/_meta/data.json[]
----
3 changes: 2 additions & 1 deletion metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ This file is generated! See scripts/mage/docs_collector.go
.2+| .2+| |<<metricbeat-metricset-kibana-stats,stats>>
|<<metricbeat-metricset-kibana-status,status>>
|<<metricbeat-module-kubernetes,Kubernetes>> |image:./images/icon-yes.png[Prebuilt dashboards are available] |
.18+| .18+| |<<metricbeat-metricset-kubernetes-apiserver,apiserver>>
.19+| .19+| |<<metricbeat-metricset-kubernetes-apiserver,apiserver>>
|<<metricbeat-metricset-kubernetes-container,container>>
|<<metricbeat-metricset-kubernetes-controllermanager,controllermanager>>
|<<metricbeat-metricset-kubernetes-event,event>>
Expand All @@ -120,6 +120,7 @@ This file is generated! See scripts/mage/docs_collector.go
|<<metricbeat-metricset-kubernetes-state_pod,state_pod>>
|<<metricbeat-metricset-kubernetes-state_replicaset,state_replicaset>>
|<<metricbeat-metricset-kubernetes-state_resourcequota,state_resourcequota>>
|<<metricbeat-metricset-kubernetes-state_service,state_service>> experimental[]
|<<metricbeat-metricset-kubernetes-state_statefulset,state_statefulset>>
|<<metricbeat-metricset-kubernetes-system,system>>
|<<metricbeat-metricset-kubernetes-volume,volume>>
Expand Down
94 changes: 82 additions & 12 deletions metricbeat/helper/prometheus/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math"
"strconv"
"strings"
"time"

"github.com/elastic/beats/libbeat/common"

Expand All @@ -37,6 +38,38 @@ type MetricMap interface {

// GetValue returns the resulting value
GetValue(m *dto.Metric) interface{}

// GetConfiguration returns the configuration for the metric
GetConfiguration() Configuration
}

// Configuration for mappings that needs extended treatment
type Configuration struct {
// StoreNonMappedLables indicates if labels found at the metric that are
// not found at the label map should be part of the resulting event.
// This setting should be used when the label name is not known beforehand
StoreNonMappedLabels bool
// NonMappedLabelsPlacement is used when StoreNonMappedLabels is set to true, and
// defines the key path at the event under which to store the dynamically found labels.
// This key path will be added to the events that match this metric along with a subset of
// key/value pairs will be created under it, one for each non mapped label found.
//
// Example:
//
// given a metric family in a prometheus resource in the form:
// metric1{label1="value1",label2="value2"} 1
// and not mapping labels but using this entry on a the MetriMap definition:
// "metric1": ExtendedInfoMetric(Configuration{StoreNonMappedLabels: true, NonMappedLabelsPlacement: "mypath"}),
// would output an event that contains a metricset field as follows
// "mypath": {"label1":"value1","label2":"value2"}
//
NonMappedLabelsPlacement string
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, this means that if StoreNonMappedLabels is set to true, and there is a metric family that contains labels whose names are not known beforehand but we are interested in pushing with our events, they will be added, and placed under the location of NonMappedLabelsPlacement

By your comment it looks like this is not clear and that I should rethink.

Would a comment like:

// NonMappedLabelsPlacement is used when StoreNonMappedLabels is set to true, and
// defines the key path at the event under which to store the dynamically found labels. This key path
// will be added to the events that match this metric and a subset of key, value pairs will be created under
// it, one for each non mapped label found

please, propose/modify which whatever you find would be clarifying

Copy link
Member

Choose a reason for hiding this comment

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

Yeap, got it now! I think it will be helpful if we add an example here showing the expected output. I see nice "examples" in the unit-tests, how about adding one in this docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ChrsMark updated

// MetricProcessing options are a set of functions that will be
// applied to metrics after they are retrieved
MetricProcessingOptions []MetricOption
// ExtraFields is used to add fields to the
// event where this metric is included
ExtraFields common.MapStr
}

// MetricOption adds settings to Metric objects behavior
Expand All @@ -57,6 +90,11 @@ func OpLowercaseValue() MetricOption {
return opLowercaseValue{}
}

// OpUnixTimestampValue parses a value into a Unix timestamp
func OpUnixTimestampValue() MetricOption {
return opUnixTimestampValue{}
}

// OpMultiplyBuckets multiplies bucket labels in histograms, useful to change units
func OpMultiplyBuckets(multiplier float64) MetricOption {
return opMultiplyBuckets{
Expand All @@ -67,8 +105,8 @@ func OpMultiplyBuckets(multiplier float64) MetricOption {
// Metric directly maps a Prometheus metric to a Metricbeat field
func Metric(field string, options ...MetricOption) MetricMap {
return &commonMetric{
field: field,
options: options,
field: field,
config: Configuration{MetricProcessingOptions: options},
}
}

Expand All @@ -77,8 +115,8 @@ func Metric(field string, options ...MetricOption) MetricMap {
func KeywordMetric(field, keyword string, options ...MetricOption) MetricMap {
return &keywordMetric{
commonMetric{
field: field,
options: options,
field: field,
config: Configuration{MetricProcessingOptions: options},
},
keyword,
}
Expand All @@ -88,8 +126,8 @@ func KeywordMetric(field, keyword string, options ...MetricOption) MetricMap {
func BooleanMetric(field string, options ...MetricOption) MetricMap {
return &booleanMetric{
commonMetric{
field: field,
options: options,
field: field,
config: Configuration{MetricProcessingOptions: options},
},
}
}
Expand All @@ -99,8 +137,8 @@ func BooleanMetric(field string, options ...MetricOption) MetricMap {
func LabelMetric(field, label string, options ...MetricOption) MetricMap {
return &labelMetric{
commonMetric{
field: field,
options: options,
field: field,
config: Configuration{MetricProcessingOptions: options},
},
label,
}
Expand All @@ -111,26 +149,50 @@ func LabelMetric(field, label string, options ...MetricOption) MetricMap {
func InfoMetric(options ...MetricOption) MetricMap {
return &infoMetric{
commonMetric{
options: options,
config: Configuration{MetricProcessingOptions: options},
},
}
}

// ExtendedInfoMetric obtains info labels from the given metric and puts them
// into events matching all the key labels present in the metric
func ExtendedInfoMetric(configuration Configuration) MetricMap {
return &infoMetric{
commonMetric{
config: configuration,
},
}
}

// ExtendedMetric is a metric item that allows extended behaviour
// through configuration
func ExtendedMetric(field string, configuration Configuration) MetricMap {
return &commonMetric{
field: field,
config: configuration,
}
}

type commonMetric struct {
field string
options []MetricOption
field string
config Configuration
}

// GetOptions returns the list of metric options
func (m *commonMetric) GetOptions() []MetricOption {
return m.options
return m.config.MetricProcessingOptions
}

// GetField returns the resulting field name
func (m *commonMetric) GetField() string {
return m.field
}

// GetConfiguration returns the configuration for the metric
func (m *commonMetric) GetConfiguration() Configuration {
return m.config
}

// GetValue returns the resulting value
func (m *commonMetric) GetValue(metric *dto.Metric) interface{} {
counter := metric.GetCounter()
Expand Down Expand Up @@ -315,3 +377,11 @@ func (o opMultiplyBuckets) Process(field string, value interface{}, labels commo
histogram["sum"] = sum * o.multiplier
return field, histogram, labels
}

type opUnixTimestampValue struct {
}

// Process converts a value in seconds into an unix time
func (o opUnixTimestampValue) Process(field string, value interface{}, labels common.MapStr) (string, interface{}, common.MapStr) {
return field, common.Time(time.Unix(int64(value.(float64)), 0)), labels
}
Loading