Skip to content

Commit

Permalink
Revert "Support Value Conversions (#172)" (#183)
Browse files Browse the repository at this point in the history
This reverts commit ca13040.
  • Loading branch information
SuperQ authored Oct 6, 2022
1 parent a8746ef commit d1456b8
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 232 deletions.
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ modules:
active: 1 # static value
count: '{.count}' # dynamic value
boolean: '{.some_boolean}'
- name: example_convert
type: object
path: '{.values[0,1]}'
labels:
state: '{.state}'
values:
state: '{.state}'
valueconverter:
'{.state}': #convert value 'state' into a number
active: 1
inactive: 2

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

$ curl "http://localhost:7979/probe?module=default&target=http://localhost:8000/examples/data.json" | grep ^example
example_convert_state{state="ACTIVE"} 1
example_convert_state{state="INACTIVE"} 2
example_global_value{environment="beta",location="planet-mars"} 1234
example_value_active{environment="beta",id="id-A"} 1
example_value_active{environment="beta",id="id-C"} 1
Expand Down
3 changes: 0 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ type Metric struct {
EpochTimestamp string
Help string
Values map[string]string
ValueConverter ValueConverterType
}

type ValueConverterType map[string]map[string]string

type ScrapeType string

const (
Expand Down
13 changes: 0 additions & 13 deletions examples/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ modules:
active: 1 # static value
count: '{.count}' # dynamic value
boolean: '{.some_boolean}'

- name: example_convert
type: object
path: '{.values[0,1]}'
labels:
state: '{.state}'
values:
state: '{.state}'
valueconverter:
'{.state}': #convert value 'state' in JSON into a number
active: 1
inactive: 2

headers:
X-Dummy: my-test-header

Expand Down
18 changes: 0 additions & 18 deletions exporter/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package exporter
import (
"bytes"
"encoding/json"
"strings"
"time"

"github.com/go-kit/log"
Expand All @@ -39,7 +38,6 @@ type JSONMetric struct {
ValueJSONPath string
LabelsJSONPaths []string
ValueType prometheus.ValueType
ValueConverter config.ValueConverterType
EpochTimestampJSONPath string
}

Expand Down Expand Up @@ -88,14 +86,11 @@ func (mc JSONMetricCollector) Collect(ch chan<- prometheus.Metric) {
continue
}
value, err := extractValue(mc.Logger, jdata, m.ValueJSONPath, false)

if err != nil {
level.Error(mc.Logger).Log("msg", "Failed to extract value for metric", "path", m.ValueJSONPath, "err", err, "metric", m.Desc)
continue
}

value = convertValueIfNeeded(m, value)

if floatValue, err := SanitizeValue(value); err == nil {
metric := prometheus.MustNewConstMetric(
m.Desc,
Expand Down Expand Up @@ -166,19 +161,6 @@ func extractLabels(logger log.Logger, data []byte, paths []string) []string {
return labels
}

// Returns the conversion of the dynamic value- if it exists in the ValueConverter configuration
func convertValueIfNeeded(m JSONMetric, value string) string {
if m.ValueConverter != nil {
if valueMappings, hasPathKey := m.ValueConverter[m.ValueJSONPath]; hasPathKey {
value = strings.ToLower(value)

if _, hasValueKey := valueMappings[value]; hasValueKey {
value = valueMappings[value]
}
}
}
return value
}
func timestampMetric(logger log.Logger, m JSONMetric, data []byte, pm prometheus.Metric) prometheus.Metric {
if m.EpochTimestampJSONPath == "" {
return pm
Expand Down
23 changes: 0 additions & 23 deletions exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ func CreateMetricsList(c config.Module) ([]JSONMetric, error) {
variableLabels = append(variableLabels, k)
variableLabelsValues = append(variableLabelsValues, v)
}

var valueConverters config.ValueConverterType = initializeValueConverter(metric)

jsonMetric := JSONMetric{
Type: config.ObjectScrape,
Desc: prometheus.NewDesc(
Expand All @@ -133,7 +130,6 @@ func CreateMetricsList(c config.Module) ([]JSONMetric, error) {
ValueJSONPath: valuePath,
LabelsJSONPaths: variableLabelsValues,
ValueType: valueType,
ValueConverter: valueConverters,
EpochTimestampJSONPath: metric.EpochTimestamp,
}
metrics = append(metrics, jsonMetric)
Expand Down Expand Up @@ -249,22 +245,3 @@ func renderBody(logger log.Logger, body config.Body, tplValues url.Values) (meth
}
return
}

// Initializes and returns a ValueConverter object. nil if there aren't any conversions
func initializeValueConverter(metric config.Metric) config.ValueConverterType {
var valueConverters config.ValueConverterType

//convert all keys to lowercase
if metric.ValueConverter != nil {
valueConverters = make(config.ValueConverterType)
for valuesKey, innerMap := range metric.ValueConverter {
//make the mappings for each value key lowercase
valueConverters[valuesKey] = make(map[string]string)
for conversionFrom, conversionTo := range innerMap {
valueConverters[valuesKey][strings.ToLower(conversionFrom)] = conversionTo
}
}
}

return valueConverters
}
116 changes: 0 additions & 116 deletions test/config/test-converter.yml

This file was deleted.

29 changes: 0 additions & 29 deletions test/response/test-converter.txt

This file was deleted.

16 changes: 0 additions & 16 deletions test/serve/test-converter.json

This file was deleted.

0 comments on commit d1456b8

Please sign in to comment.