MCPcopy Index your code
hub / github.com/cortexproject/cortex / Push

Method Push

integration/e2ecortex/client.go:168–198  ·  view source on GitHub ↗

Push the input timeseries to the remote endpoint

(timeseries []prompb.TimeSeries, metadata ...prompb.MetricMetadata)

Source from the content-addressed store, hash-verified

166
167// Push the input timeseries to the remote endpoint
168func (c *Client) Push(timeseries []prompb.TimeSeries, metadata ...prompb.MetricMetadata) (*http.Response, error) {
169 // Create write request
170 data, err := proto.Marshal(&prompb.WriteRequest{Timeseries: timeseries, Metadata: metadata})
171 if err != nil {
172 return nil, err
173 }
174
175 // Create HTTP request
176 compressed := snappy.Encode(nil, data)
177 req, err := http.NewRequest("POST", fmt.Sprintf("http://%s/api/prom/push", c.distributorAddress), bytes.NewReader(compressed))
178 if err != nil {
179 return nil, err
180 }
181
182 req.Header.Add("Content-Encoding", "snappy")
183 req.Header.Set("Content-Type", "application/x-protobuf")
184 req.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
185 req.Header.Set("X-Scope-OrgID", c.orgID)
186
187 ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
188 defer cancel()
189
190 // Execute HTTP request
191 res, err := c.httpClient.Do(req.WithContext(ctx))
192 if err != nil {
193 return nil, err
194 }
195
196 defer res.Body.Close()
197 return res, nil
198}
199
200// PushV2 the input timeseries to the remote endpoint
201func (c *Client) PushV2(symbols []string, timeseries []writev2.TimeSeries) (remoteapi.WriteResponseStats, error) {

Calls 6

EncodeMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
MarshalMethod · 0.45
AddMethod · 0.45