storage/remote/client.go
func (c *Client) Store(ctx context.Context, req []byte) error {
	httpReq, err := http.NewRequest("POST", c.url.String(), bytes.NewReader(req))
	if err != nil {
		// Errors from NewRequest are from unparseable URLs, so are not
		// recoverable.
		return err
	}
	httpReq.Header.Add("Content-Encoding", "snappy")
	httpReq.Header.Set("Content-Type", "application/x-protobuf")
	httpReq.Header.Set("User-Agent", userAgent)
	httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
	httpReq = httpReq.WithContext(ctx)

	ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
	defer cancel()

	httpResp, err := c.client.Do(httpReq.WithContext(ctx))
	if err != nil {
		// Errors from client.Do are from (for example) network errors, so are
		// recoverable.
		return recoverableError{err}
	}
	defer func() {
		io.Copy(ioutil.Discard, httpResp.Body)
		httpResp.Body.Close()
	}()

	if httpResp.StatusCode/100 != 2 {
		scanner := bufio.NewScanner(io.LimitReader(httpResp.Body, maxErrMsgLen))
		line := ""
		if scanner.Scan() {
			line = scanner.Text()
		}
		err = errors.Errorf("server returned HTTP status %s: %s", httpResp.Status, line)
	}
	if httpResp.StatusCode/100 == 5 {
		return recoverableError{err}
	}
	return err
}
func (c *Client) Store(ctx context.Context, req []byte) error {
	httpReq, err := http.NewRequest("POST", c.url.String(), bytes.NewReader(req))
	if err != nil {
		// Errors from NewRequest are from unparseable URLs, so are not
		// recoverable.
		return err
	}
	httpReq.Header.Add("Content-Encoding", "snappy")
	httpReq.Header.Set("Content-Type", "application/x-protobuf")
	httpReq.Header.Set("User-Agent", userAgent)
	httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
	httpReq = httpReq.WithContext(ctx)

	ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
	defer cancel()

	httpResp, err := c.client.Do(httpReq.WithContext(ctx))
	if err != nil {
		// Errors from client.Do are from (for example) network errors, so are
		// recoverable.
		return recoverableError{err}
	}
	defer func() {
		io.Copy(ioutil.Discard, httpResp.Body)
		httpResp.Body.Close()
	}()

	if httpResp.StatusCode/100 != 2 {
		scanner := bufio.NewScanner(io.LimitReader(httpResp.Body, maxErrMsgLen))
		line := ""
		if scanner.Scan() {
			line = scanner.Text()
		}
		err = errors.Errorf("server returned HTTP status %s: %s", httpResp.Status, line)
	}
	if httpResp.StatusCode/100 == 5 {
		return recoverableError{err}
	}
	return err
}
func ( c * Client ) Store ( ctx context . Context , req [ ] byte ) error { httpReq , err := http . NewRequest ( " " , c . url . String ( ) , bytes . NewReader ( req ) ) if err != nil { // Errors from NewRequest are from unparseable URLs, so are not // recoverable. return err } httpReq . Header . Add ( " " , " " ) httpReq . Header . Set ( " " , " " ) httpReq . Header . Set ( " " , userAgent ) httpReq . Header . Set ( " " , " " ) httpReq = httpReq . WithContext ( ctx ) ctx , cancel := context . WithTimeout ( context . Background ( ) , c . timeout ) defer cancel ( ) httpResp , err := c . client . Do ( httpReq . WithContext ( ctx ) ) if err != nil { // Errors from client.Do are from (for example) network errors, so are // recoverable. return recoverableError { err } } defer func ( ) { io . Copy ( ioutil . Discard , httpResp . Body ) httpResp . Body . Close ( ) } ( ) if httpResp . StatusCode / 100 != 2 { scanner := bufio . NewScanner ( io . LimitReader ( httpResp . Body , maxErrMsgLen ) ) line := " " if scanner . Scan ( ) { line = scanner . Text ( ) } err = errors . Errorf ( " " , httpResp . Status , line ) } if httpResp . StatusCode / 100 == 5 { return recoverableError { err } } return err }
// Store sends a batch of samples to the HTTP endpoint, the request is the proto marshalled
// and encoded bytes from codec.go.
Store sends a batch of samples to the HTTP endpoint the request is the proto marshalled and encoded bytes from codec . go .