@@ -3,6 +3,7 @@ package gather
3
3
import (
4
4
"context"
5
5
"net/http/httptest"
6
+ "strings"
6
7
"testing"
7
8
"time"
8
9
@@ -11,6 +12,7 @@ import (
11
12
"github.com/influxdata/influxdb/v2/mock"
12
13
"github.com/influxdata/influxdb/v2/models"
13
14
influxdbtesting "github.com/influxdata/influxdb/v2/testing"
15
+ dto "github.com/prometheus/client_model/go"
14
16
"github.com/stretchr/testify/assert"
15
17
"github.com/stretchr/testify/require"
16
18
"go.uber.org/zap/zaptest"
@@ -77,3 +79,46 @@ const sampleRespSmall = `
77
79
# TYPE go_goroutines gauge
78
80
go_goroutines 36
79
81
`
82
+
83
+ func TestMetricsToPoints (t * testing.T ) {
84
+ const overflow = 3
85
+ const goodPoints = 2
86
+ tags := map [string ]string {"one" : "first" , "two" : "second" , "three" : "third" }
87
+ fields := map [string ]interface {}{"first_field" : 32.2 }
88
+
89
+ ms := MetricsSlice {
90
+ {
91
+ Name : "a" ,
92
+ Tags : tags ,
93
+ Fields : fields ,
94
+ Timestamp : time .Now (),
95
+ Type : dto .MetricType_GAUGE ,
96
+ },
97
+ {
98
+ Name : "b" ,
99
+ Tags : tags ,
100
+ Fields : fields ,
101
+ Timestamp : time .Now (),
102
+ Type : dto .MetricType_GAUGE ,
103
+ }, {
104
+ Name : strings .Repeat ("c" , models .MaxKeyLength + overflow ),
105
+ Tags : tags ,
106
+ Fields : fields ,
107
+ Timestamp : time .Now (),
108
+ Type : dto .MetricType_GAUGE ,
109
+ },
110
+ {
111
+ Name : "d" ,
112
+ Tags : tags ,
113
+ Fields : fields ,
114
+ Timestamp : time .Now (),
115
+ Type : dto .MetricType_GAUGE ,
116
+ },
117
+ }
118
+ ps , err := ms .Points ()
119
+ assert .ErrorContains (t , err , "max key length exceeded" , "MetricSlice.Points did not have a 'max key length exceeded' error" )
120
+ assert .Equal (t , goodPoints , len (ps ), "wrong number of Points returned from MetricSlice.Points" )
121
+ for _ , p := range ps {
122
+ assert .NotNil (t , p , "nil Point object returned from MetricSlice.Points" )
123
+ }
124
+ }
0 commit comments