Skip to content

Commit

Permalink
Use textparse in prometheus module helper library (#33865)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrsMark authored Jan 25, 2023
1 parent 5ed9f16 commit 9754d2b
Show file tree
Hide file tree
Showing 33 changed files with 1,274 additions and 1,206 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,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

0 comments on commit 9754d2b

Please sign in to comment.