Skip to content

Commit 8986d24

Browse files
authored
Revert "Support Value Conversions (#172)"
This reverts commit ca13040.
1 parent a8746ef commit 8986d24

File tree

8 files changed

+0
-232
lines changed

8 files changed

+0
-232
lines changed

Diff for: README.md

-14
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@ modules:
6060
active: 1 # static value
6161
count: '{.count}' # dynamic value
6262
boolean: '{.some_boolean}'
63-
64-
- name: example_convert
65-
type: object
66-
path: '{.values[0,1]}'
67-
labels:
68-
state: '{.state}'
69-
values:
70-
state: '{.state}'
71-
valueconverter:
72-
'{.state}': #convert value 'state' into a number
73-
active: 1
74-
inactive: 2
7563

7664
headers:
7765
X-Dummy: my-test-header
@@ -82,8 +70,6 @@ Serving HTTP on 0.0.0.0 port 8000 ...
8270
$ ./json_exporter --config.file examples/config.yml &
8371

8472
$ curl "http://localhost:7979/probe?module=default&target=http://localhost:8000/examples/data.json" | grep ^example
85-
example_convert_state{state="ACTIVE"} 1
86-
example_convert_state{state="INACTIVE"} 2
8773
example_global_value{environment="beta",location="planet-mars"} 1234
8874
example_value_active{environment="beta",id="id-A"} 1
8975
example_value_active{environment="beta",id="id-C"} 1

Diff for: config/config.go

-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ type Metric struct {
3030
EpochTimestamp string
3131
Help string
3232
Values map[string]string
33-
ValueConverter ValueConverterType
3433
}
3534

36-
type ValueConverterType map[string]map[string]string
37-
3835
type ScrapeType string
3936

4037
const (

Diff for: examples/config.yml

-13
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@ modules:
2525
active: 1 # static value
2626
count: '{.count}' # dynamic value
2727
boolean: '{.some_boolean}'
28-
29-
- name: example_convert
30-
type: object
31-
path: '{.values[0,1]}'
32-
labels:
33-
state: '{.state}'
34-
values:
35-
state: '{.state}'
36-
valueconverter:
37-
'{.state}': #convert value 'state' in JSON into a number
38-
active: 1
39-
inactive: 2
40-
4128
headers:
4229
X-Dummy: my-test-header
4330

Diff for: exporter/collector.go

-18
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package exporter
1616
import (
1717
"bytes"
1818
"encoding/json"
19-
"strings"
2019
"time"
2120

2221
"github.com/go-kit/log"
@@ -39,7 +38,6 @@ type JSONMetric struct {
3938
ValueJSONPath string
4039
LabelsJSONPaths []string
4140
ValueType prometheus.ValueType
42-
ValueConverter config.ValueConverterType
4341
EpochTimestampJSONPath string
4442
}
4543

@@ -88,14 +86,11 @@ func (mc JSONMetricCollector) Collect(ch chan<- prometheus.Metric) {
8886
continue
8987
}
9088
value, err := extractValue(mc.Logger, jdata, m.ValueJSONPath, false)
91-
9289
if err != nil {
9390
level.Error(mc.Logger).Log("msg", "Failed to extract value for metric", "path", m.ValueJSONPath, "err", err, "metric", m.Desc)
9491
continue
9592
}
9693

97-
value = convertValueIfNeeded(m, value)
98-
9994
if floatValue, err := SanitizeValue(value); err == nil {
10095
metric := prometheus.MustNewConstMetric(
10196
m.Desc,
@@ -166,19 +161,6 @@ func extractLabels(logger log.Logger, data []byte, paths []string) []string {
166161
return labels
167162
}
168163

169-
// Returns the conversion of the dynamic value- if it exists in the ValueConverter configuration
170-
func convertValueIfNeeded(m JSONMetric, value string) string {
171-
if m.ValueConverter != nil {
172-
if valueMappings, hasPathKey := m.ValueConverter[m.ValueJSONPath]; hasPathKey {
173-
value = strings.ToLower(value)
174-
175-
if _, hasValueKey := valueMappings[value]; hasValueKey {
176-
value = valueMappings[value]
177-
}
178-
}
179-
}
180-
return value
181-
}
182164
func timestampMetric(logger log.Logger, m JSONMetric, data []byte, pm prometheus.Metric) prometheus.Metric {
183165
if m.EpochTimestampJSONPath == "" {
184166
return pm

Diff for: exporter/util.go

-23
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ func CreateMetricsList(c config.Module) ([]JSONMetric, error) {
118118
variableLabels = append(variableLabels, k)
119119
variableLabelsValues = append(variableLabelsValues, v)
120120
}
121-
122-
var valueConverters config.ValueConverterType = initializeValueConverter(metric)
123-
124121
jsonMetric := JSONMetric{
125122
Type: config.ObjectScrape,
126123
Desc: prometheus.NewDesc(
@@ -133,7 +130,6 @@ func CreateMetricsList(c config.Module) ([]JSONMetric, error) {
133130
ValueJSONPath: valuePath,
134131
LabelsJSONPaths: variableLabelsValues,
135132
ValueType: valueType,
136-
ValueConverter: valueConverters,
137133
EpochTimestampJSONPath: metric.EpochTimestamp,
138134
}
139135
metrics = append(metrics, jsonMetric)
@@ -249,22 +245,3 @@ func renderBody(logger log.Logger, body config.Body, tplValues url.Values) (meth
249245
}
250246
return
251247
}
252-
253-
// Initializes and returns a ValueConverter object. nil if there aren't any conversions
254-
func initializeValueConverter(metric config.Metric) config.ValueConverterType {
255-
var valueConverters config.ValueConverterType
256-
257-
//convert all keys to lowercase
258-
if metric.ValueConverter != nil {
259-
valueConverters = make(config.ValueConverterType)
260-
for valuesKey, innerMap := range metric.ValueConverter {
261-
//make the mappings for each value key lowercase
262-
valueConverters[valuesKey] = make(map[string]string)
263-
for conversionFrom, conversionTo := range innerMap {
264-
valueConverters[valuesKey][strings.ToLower(conversionFrom)] = conversionTo
265-
}
266-
}
267-
}
268-
269-
return valueConverters
270-
}

Diff for: test/config/test-converter.yml

-116
This file was deleted.

Diff for: test/response/test-converter.txt

-29
This file was deleted.

Diff for: test/serve/test-converter.json

-16
This file was deleted.

0 commit comments

Comments
 (0)