@@ -74,92 +74,11 @@ type PreallocWriteRequest struct {
74
74
func (p * PreallocWriteRequest ) Unmarshal (dAtA []byte ) error {
75
75
p .Timeseries = PreallocTimeseriesSliceFromPool ()
76
76
p .WriteRequest .skipUnmarshalingExemplars = p .SkipUnmarshalingExemplars
77
-
78
- if p .UnmarshalFromRW2 {
79
- return p .unmarshalRW2 (dAtA )
80
- }
77
+ p .WriteRequest .UnmarshalFromRW2 = p .UnmarshalFromRW2
81
78
82
79
return p .WriteRequest .Unmarshal (dAtA )
83
80
}
84
81
85
- // UnmarshalRW2 unmarshals the given remote write 2.0 data and converts it to a WriteRequest.
86
- func (p * PreallocWriteRequest ) unmarshalRW2 (data []byte ) error {
87
- rw2req := & WriteRequestRW2 {}
88
- rw2req .skipUnmarshalingExemplars = p .SkipUnmarshalingExemplars
89
- if err := rw2req .Unmarshal (data ); err != nil {
90
- return err
91
- }
92
-
93
- metricFamilies := map [string ]* MetricMetadata {}
94
-
95
- for _ , ts := range rw2req .Timeseries {
96
- p .Timeseries = append (p .Timeseries , PreallocTimeseries {})
97
- p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries = TimeseriesFromPool ()
98
- p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries .CreatedTimestamp = ts .CreatedTimestamp
99
- var err error
100
- p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries .Labels , err = labelRefsToLabelAdapter (ts .LabelsRefs , rw2req .Symbols )
101
- if err != nil {
102
- return err
103
- }
104
- p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries .Samples = ts .Samples
105
- p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries .Histograms = ts .Histograms
106
- if len (ts .Exemplars ) > 0 {
107
- p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries .Exemplars = make ([]Exemplar , 0 , len (ts .Exemplars ))
108
- for i := range ts .Exemplars {
109
- lbls , err := labelRefsToLabelAdapter (ts .Exemplars [i ].LabelsRefs , rw2req .Symbols )
110
- if err != nil {
111
- return err
112
- }
113
- p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries .Exemplars = append (p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries .Exemplars , Exemplar {
114
- Labels : lbls ,
115
- Value : ts .Exemplars [i ].Value ,
116
- TimestampMs : ts .Exemplars [i ].Timestamp ,
117
- })
118
- }
119
- }
120
-
121
- // Convert RW2 metadata to RW1 metadata.
122
- seriesName := getSeriesName (p .Timeseries [len (p .Timeseries )- 1 ].TimeSeries .Labels )
123
- if seriesName == "" {
124
- continue
125
- }
126
- metricFamily , _ := getMetricName (seriesName , ts .Metadata .Type )
127
- if metricFamily == "" {
128
- continue
129
- }
130
- help , _ := getSymbol (ts .Metadata .HelpRef , rw2req .Symbols )
131
- unit , _ := getSymbol (ts .Metadata .UnitRef , rw2req .Symbols )
132
-
133
- if ts .Metadata .Type == METRIC_TYPE_UNSPECIFIED && help == "" && unit == "" {
134
- // Nothing to do here.
135
- continue
136
- }
137
-
138
- metricFamilies [metricFamily ] = & MetricMetadata {
139
- Type : MetricMetadata_MetricType (ts .Metadata .Type ),
140
- MetricFamilyName : metricFamily ,
141
- Help : help ,
142
- Unit : unit ,
143
- }
144
- }
145
-
146
- // Fill the metadata
147
- p .Metadata = make ([]* MetricMetadata , 0 , len (metricFamilies ))
148
- for _ , metadata := range metricFamilies {
149
- p .Metadata = append (p .Metadata , metadata )
150
- }
151
-
152
- return nil
153
- }
154
-
155
- // getSymbol resolves the symbol reference to a string.
156
- func getSymbol (ref uint32 , symbols []string ) (string , error ) {
157
- if ref < uint32 (len (symbols )) {
158
- return symbols [ref ], nil
159
- }
160
- return "" , fmt .Errorf ("symbol reference %d is out of bounds" , ref )
161
- }
162
-
163
82
// labelRefsToLabelAdapter converts a slice of label references to a slice
164
83
// of LabelAdapter.
165
84
func labelRefsToLabelAdapter (refs []uint32 , symbols []string ) ([]LabelAdapter , error ) {
@@ -168,11 +87,11 @@ func labelRefsToLabelAdapter(refs []uint32, symbols []string) ([]LabelAdapter, e
168
87
}
169
88
labels := make ([]LabelAdapter , 0 , len (refs )/ 2 )
170
89
for i := 0 ; i < len (refs ); i += 2 {
171
- name , err := getSymbol (refs [i ], symbols )
90
+ name , err := getRW2Symbol (refs [i ], symbols )
172
91
if err != nil {
173
92
return nil , err
174
93
}
175
- value , err := getSymbol (refs [i + 1 ], symbols )
94
+ value , err := getRW2Symbol (refs [i + 1 ], symbols )
176
95
if err != nil {
177
96
return nil , err
178
97
}
@@ -254,6 +173,7 @@ type PreallocTimeseries struct {
254
173
marshalledData []byte
255
174
256
175
skipUnmarshalingExemplars bool
176
+ unmarshalFromRW2 bool
257
177
}
258
178
259
179
// RemoveLabel removes the label labelName from this timeseries, if it exists.
@@ -376,13 +296,15 @@ var TimeseriesUnmarshalCachingEnabled = true
376
296
// Unmarshal implements proto.Message. Input data slice is retained.
377
297
// Copied from the protobuf generated code, the only change is that in case 3 the exemplars don't get unmarshaled
378
298
// if p.skipUnmarshalingExemplars is false.
379
- func (p * PreallocTimeseries ) Unmarshal (dAtA []byte ) error {
380
- if TimeseriesUnmarshalCachingEnabled {
299
+ func (p * PreallocTimeseries ) Unmarshal (dAtA []byte , symbols []string ) error {
300
+ if TimeseriesUnmarshalCachingEnabled && ! p .unmarshalFromRW2 {
301
+ // TODO(krajorama): check if it makes sense for RW2 as well.
381
302
p .marshalledData = dAtA
382
303
}
383
304
p .TimeSeries = TimeseriesFromPool ()
384
305
p .TimeSeries .SkipUnmarshalingExemplars = p .skipUnmarshalingExemplars
385
- return p .TimeSeries .Unmarshal (dAtA )
306
+ p .TimeSeries .UnmarshalFromRW2 = p .unmarshalFromRW2
307
+ return p .TimeSeries .Unmarshal (dAtA , symbols )
386
308
}
387
309
388
310
func (p * PreallocTimeseries ) Size () int {
0 commit comments