Refactor InfluxDB listener (#6974)
Use streaming parser in InfluxDB listener
This commit is contained in:
@@ -17,6 +17,8 @@ import (
|
||||
var fieldEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
|
||||
var keyEscaper = strings.NewReplacer(" ", "\\ ", ",", "\\,", "=", "\\=")
|
||||
|
||||
type TimeFunc func() time.Time
|
||||
|
||||
// Parser parses json inputs containing dropwizard metrics,
|
||||
// either top-level or embedded inside a json field.
|
||||
// This parser is using gjson for retrieving paths within the json file.
|
||||
@@ -48,7 +50,7 @@ type parser struct {
|
||||
separator string
|
||||
templateEngine *templating.Engine
|
||||
|
||||
timeFunc metric.TimeFunc
|
||||
timeFunc TimeFunc
|
||||
|
||||
// seriesParser parses line protocol measurement + tags
|
||||
seriesParser *influx.Parser
|
||||
@@ -267,6 +269,6 @@ func (p *parser) readDWMetrics(metricType string, dwms interface{}, metrics []te
|
||||
return metrics
|
||||
}
|
||||
|
||||
func (p *parser) SetTimeFunc(f metric.TimeFunc) {
|
||||
func (p *parser) SetTimeFunc(f TimeFunc) {
|
||||
p.timeFunc = f
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var TimeFunc = func() time.Time {
|
||||
var testTimeFunc = func() time.Time {
|
||||
return time.Unix(0, 0)
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ func TestDropWizard(t *testing.T) {
|
||||
map[string]interface{}{
|
||||
"value": 42.0,
|
||||
},
|
||||
TimeFunc(),
|
||||
testTimeFunc(),
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -547,7 +547,7 @@ func TestDropWizard(t *testing.T) {
|
||||
map[string]interface{}{
|
||||
"value": 42.0,
|
||||
},
|
||||
TimeFunc(),
|
||||
testTimeFunc(),
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -573,7 +573,7 @@ func TestDropWizard(t *testing.T) {
|
||||
map[string]interface{}{
|
||||
"value": 42.0,
|
||||
},
|
||||
TimeFunc(),
|
||||
testTimeFunc(),
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -584,7 +584,7 @@ func TestDropWizard(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
parser := NewParser()
|
||||
parser.SetTimeFunc(TimeFunc)
|
||||
parser.SetTimeFunc(testTimeFunc)
|
||||
metrics, err := parser.Parse(tt.input)
|
||||
tt.errFunc(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user