@@ -5,10 +5,9 @@ import (
5
5
"fmt"
6
6
"net/http"
7
7
"strconv"
8
- "strings"
9
8
10
9
"github.com/go-kit/log/level"
11
- "github.com/prometheus/prometheus/config "
10
+ "github.com/prometheus/client_golang/exp/api/remote "
12
11
"github.com/prometheus/prometheus/model/labels"
13
12
writev2 "github.com/prometheus/prometheus/prompb/io/prometheus/write/v2"
14
13
"github.com/prometheus/prometheus/util/compression"
@@ -125,14 +124,14 @@ func Handler(remoteWrite2Enabled bool, maxRecvMsgSize int, sourceIPs *middleware
125
124
contentType = appProtoContentType
126
125
}
127
126
128
- msgType , err := parseProtoMsg (contentType )
127
+ msgType , err := remote . ParseProtoMsg (contentType )
129
128
if err != nil {
130
129
level .Error (logger ).Log ("Error decoding remote write request" , "err" , err )
131
130
http .Error (w , err .Error (), http .StatusUnsupportedMediaType )
132
131
return
133
132
}
134
133
135
- if msgType != config . RemoteWriteProtoMsgV1 && msgType != config . RemoteWriteProtoMsgV2 {
134
+ if msgType != remote . WriteV1MessageType && msgType != remote . WriteV2MessageType {
136
135
level .Error (logger ).Log ("Not accepted msg type" , "msgType" , msgType , "err" , err )
137
136
http .Error (w , err .Error (), http .StatusUnsupportedMediaType )
138
137
return
@@ -148,9 +147,9 @@ func Handler(remoteWrite2Enabled bool, maxRecvMsgSize int, sourceIPs *middleware
148
147
}
149
148
150
149
switch msgType {
151
- case config . RemoteWriteProtoMsgV1 :
150
+ case remote . WriteV1MessageType :
152
151
handlePRW1 ()
153
- case config . RemoteWriteProtoMsgV2 :
152
+ case remote . WriteV2MessageType :
154
153
handlePRW2 ()
155
154
}
156
155
} else {
@@ -165,32 +164,6 @@ func setPRW2RespHeader(w http.ResponseWriter, samples, histograms, exemplars int
165
164
w .Header ().Set (rw20WrittenExemplarsHeader , strconv .FormatInt (exemplars , 10 ))
166
165
}
167
166
168
- // Refer to parseProtoMsg in https://github.com/prometheus/prometheus/blob/main/storage/remote/write_handler.go
169
- func parseProtoMsg (contentType string ) (config.RemoteWriteProtoMsg , error ) {
170
- contentType = strings .TrimSpace (contentType )
171
-
172
- parts := strings .Split (contentType , ";" )
173
- if parts [0 ] != appProtoContentType {
174
- return "" , fmt .Errorf ("expected %v as the first (media) part, got %v content-type" , appProtoContentType , contentType )
175
- }
176
- // Parse potential https://www.rfc-editor.org/rfc/rfc9110#parameter
177
- for _ , p := range parts [1 :] {
178
- pair := strings .Split (p , "=" )
179
- if len (pair ) != 2 {
180
- return "" , fmt .Errorf ("as per https://www.rfc-editor.org/rfc/rfc9110#parameter expected parameters to be key-values, got %v in %v content-type" , p , contentType )
181
- }
182
- if pair [0 ] == "proto" {
183
- ret := config .RemoteWriteProtoMsg (pair [1 ])
184
- if err := ret .Validate (); err != nil {
185
- return "" , fmt .Errorf ("got %v content type; %w" , contentType , err )
186
- }
187
- return ret , nil
188
- }
189
- }
190
- // No "proto=" parameter, assuming v1.
191
- return config .RemoteWriteProtoMsgV1 , nil
192
- }
193
-
194
167
func convertV2RequestToV1 (req * writev2.Request ) (cortexpb.PreallocWriteRequest , error ) {
195
168
var v1Req cortexpb.PreallocWriteRequest
196
169
v1Timeseries := make ([]cortexpb.PreallocTimeseries , 0 , len (req .Timeseries ))
0 commit comments