Push the input timeseries to the remote endpoint
(timeseries []prompb.TimeSeries, metadata ...prompb.MetricMetadata)
| 166 | |
| 167 | // Push the input timeseries to the remote endpoint |
| 168 | func (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 |
| 201 | func (c *Client) PushV2(symbols []string, timeseries []writev2.TimeSeries) (remoteapi.WriteResponseStats, error) { |