Skip to content

Commit

Permalink
Additional tests, remove println
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Mar 11, 2024
1 parent c71a631 commit 948444d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
15 changes: 6 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,6 @@ require (
modernc.org/sqlite v1.29.2
)

require (
github.com/aws/aws-sdk-go v1.45.25 // indirect
github.com/dennwc/varint v1.0.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
)

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
Expand Down Expand Up @@ -271,6 +262,7 @@ require (
github.com/aristanetworks/glog v0.0.0-20191112221043-67e8567f59f3 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/awnumar/memcall v0.2.0 // indirect
github.com/aws/aws-sdk-go v1.45.25 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.13.7 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.7 // indirect
Expand Down Expand Up @@ -306,6 +298,7 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dennwc/varint v1.0.0 // indirect
github.com/devigned/tab v0.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.5.0 // indirect
Expand All @@ -322,6 +315,7 @@ require (
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.5 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
Expand Down Expand Up @@ -349,6 +343,7 @@ require (
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/schema v1.2.1 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/grid-x/serial v0.0.0-20211107191517-583c7356b3aa // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
Expand Down Expand Up @@ -410,6 +405,7 @@ require (
github.com/mtibben/percent v0.2.1 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/nats-io/jwt/v2 v2.5.3 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
Expand All @@ -428,6 +424,7 @@ require (
github.com/pkg/sftp v1.13.6 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff // indirect
Expand Down
8 changes: 4 additions & 4 deletions plugins/parsers/prometheusremotewrite/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
} else {
h = remote.HistogramProtoToFloatHistogram(hp)
}

if hp.Timestamp > 0 {
t = time.Unix(0, hp.Timestamp*1000000)
}
Expand All @@ -86,19 +87,18 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
iter := h.AllBucketIterator()
for iter.Next() {
bucket := iter.At()
fmt.Println(bucket.String())
fields = make(map[string]interface{}, 1)
fields[metricName] = bucket.Count
localTags := make(map[string]string, len(tags)+1)
localTags[metricName+"_le"] = fmt.Sprintf("%g", bucket.Upper)
for k, v := range tags {
localTags[k] = v
}
fields = make(map[string]interface{})
fields[metricName] = bucket.Count

m := metric.New("prometheus_remote_write", localTags, fields, t)
metrics = append(metrics, m)
}
}
fmt.Println()
}
return metrics, err
}
Expand Down
49 changes: 45 additions & 4 deletions plugins/parsers/prometheusremotewrite/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,45 @@ func generateTestHistogram(i int) *histogram.Histogram {
}
}

func generateTestFloatHistogram(i int) *histogram.FloatHistogram {
return &histogram.FloatHistogram{
Count: 12 + float64(i*9),
ZeroCount: 2 + float64(i),
ZeroThreshold: 0.001,
Sum: 18.4 * float64(i+1),
Schema: 1,
PositiveSpans: []histogram.Span{
{Offset: 0, Length: 2},
{Offset: 1, Length: 2},
},
PositiveBuckets: []float64{float64(i + 1), float64(i + 2), float64(i + 1), float64(i + 1)},
NegativeSpans: []histogram.Span{
{Offset: 0, Length: 2},
{Offset: 1, Length: 2},
},
NegativeBuckets: []float64{float64(i + 1), float64(i + 2), float64(i + 1), float64(i + 1)},
}
}

func TestHistograms(t *testing.T) {
//histograms :=
prompbInput := prompb.WriteRequest{
Timeseries: []prompb.TimeSeries{
{
Labels: []prompb.Label{
{Name: "__name__", Value: "test_metric_seconds"},
},
Histograms: []prompb.Histogram{
// Use this for float testing
//remote.FloatHistogramToHistogramProto(0, generateTestFloatHistogram(1))
remote.HistogramToHistogramProto(0, generateTestHistogram(1)),
},
},
{
Labels: []prompb.Label{
{Name: "__name__", Value: "test_float_metric_seconds"},
},
Histograms: []prompb.Histogram{
remote.FloatHistogramToHistogramProto(0, generateTestFloatHistogram(2)),
},
},
},
}

Expand All @@ -131,14 +156,30 @@ func TestHistograms(t *testing.T) {
},
time.Unix(0, 0),
),
testutil.MustMetric(
"prometheus_remote_write",
map[string]string{},
map[string]interface{}{
"test_float_metric_seconds_sum": float64(55.199999999999996),
},
time.Unix(0, 0),
),
testutil.MustMetric(
"prometheus_remote_write",
map[string]string{},
map[string]interface{}{
"test_float_metric_seconds_count": float64(30),
},
time.Unix(0, 0),
),
}

parser := Parser{
DefaultTags: map[string]string{},
}
metrics, err := parser.Parse(inoutBytes)
require.NoError(t, err)
require.Len(t, metrics, 11)
require.Len(t, metrics, 22)
testutil.RequireMetricsSubset(t, expected, metrics, testutil.IgnoreTime(), testutil.SortMetrics())
}

Expand Down

0 comments on commit 948444d

Please sign in to comment.