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

Use textparse in prometheus module helper library #33865

Merged
merged 22 commits into from
Jan 25, 2023
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 @@ -190,6 +190,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Add GCP Redis regions support {pull}33728[33728]
- Add namespace metadata to all namespaced kubernetes resources. {pull}33763[33763]
- Changed cloudwatch module to call ListMetrics API only once per region, instead of per AWS namespace {pull}34055[34055]
- Handle duplicated TYPE line for prometheus metrics {issue}18813[18813] {pull}33865[33865]

*Packetbeat*

Expand Down
18 changes: 10 additions & 8 deletions metricbeat/helper/openmetrics/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"strings"
"time"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/elastic-agent-libs/mapstr"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/metricbeat/helper/prometheus"
)

// MetricMap defines the mapping from Openmetrics metric to a Metricbeat field
Expand All @@ -37,7 +39,7 @@ type MetricMap interface {
GetField() string

// GetValue returns the resulting value
GetValue(m *OpenMetric) interface{}
GetValue(m *prometheus.OpenMetric) interface{}
GetNilValue() interface{}

// GetConfiguration returns the configuration for the metric
Expand Down Expand Up @@ -207,7 +209,7 @@ func (m *commonMetric) GetNilValue() interface{} {
}

// GetValue returns the resulting value
func (m *commonMetric) GetValue(metric *OpenMetric) interface{} {
func (m *commonMetric) GetValue(metric *prometheus.OpenMetric) interface{} {
info := metric.GetInfo()
if info != nil {
if info.HasValidValue() {
Expand Down Expand Up @@ -325,7 +327,7 @@ type keywordMetric struct {
}

// GetValue returns the resulting value
func (m *keywordMetric) GetValue(metric *OpenMetric) interface{} {
func (m *keywordMetric) GetValue(metric *prometheus.OpenMetric) interface{} {
if gauge := metric.GetGauge(); gauge != nil && gauge.GetValue() == 1 {
return m.keyword
}
Expand All @@ -337,7 +339,7 @@ type booleanMetric struct {
}

// GetValue returns the resulting value
func (m *booleanMetric) GetValue(metric *OpenMetric) interface{} {
func (m *booleanMetric) GetValue(metric *prometheus.OpenMetric) interface{} {
if gauge := metric.GetGauge(); gauge != nil {
return gauge.GetValue() == 1
}
Expand All @@ -350,14 +352,14 @@ type labelMetric struct {
}

// GetValue returns the resulting value
func (m *labelMetric) GetValue(metric *OpenMetric) interface{} {
func (m *labelMetric) GetValue(metric *prometheus.OpenMetric) interface{} {
if gauge := metric.GetGauge(); gauge != nil && gauge.GetValue() == 1 {
return getLabel(metric, m.label)
}
return nil
}

func getLabel(metric *OpenMetric, name string) string {
func getLabel(metric *prometheus.OpenMetric, name string) string {
for _, label := range metric.GetLabel() {
if label.Name == name {
return label.Value
Expand All @@ -371,7 +373,7 @@ type infoMetric struct {
}

// GetValue returns the resulting value
func (m *infoMetric) GetValue(metric *OpenMetric) interface{} {
func (m *infoMetric) GetValue(metric *prometheus.OpenMetric) interface{} {
return ""
}

Expand Down
Loading