Skip to content

Commit

Permalink
Merge branch 'main' into feat/export-telemetrygen-funcs-for-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Erog38 authored Jan 31, 2025
2 parents 831566a + 94415c9 commit 960d21c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
Triagers ([@open-telemetry/collector-contrib-triagers](https://github.com/orgs/open-telemetry/teams/collector-contrib-triagers))

- [Benedikt Bongartz](https://github.com/frzifus), Red Hat
- [Braydon Kains](https://github.com/braydonk), Google
- [Florian Bacher](https://github.com/bacherfl), Dynatrace
- [James Moessis](https://github.com/jamesmoessis), Atlassian
- [Jared Tan](https://github.com/JaredTan95), DaoCloud
- [Murphy Chen](https://github.com/Frapschen), DaoCloud
- [Paulo Janotti](https://github.com/pjanotti), Splunk
- [Vihas Makwana](https://github.com/VihasMakwana), Elastic
- [Braydon Kains](https://github.com/braydonk), Google
- [James Moessis](https://github.com/jamesmoessis), Atlassian
- Actively seeking contributors to triage issues

Emeritus Triagers:
Expand Down
28 changes: 8 additions & 20 deletions receiver/prometheusremotewritereceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"

"github.com/gogo/protobuf/proto"
Expand All @@ -16,7 +17,6 @@ import (
writev2 "github.com/prometheus/prometheus/prompb/io/prometheus/write/v2"
"github.com/prometheus/prometheus/storage/remote"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver/receivertest"
Expand Down Expand Up @@ -58,22 +58,7 @@ func setupMetricsReceiver(t *testing.T) *prometheusRemoteWriteReceiver {
return prwReceiver.(*prometheusRemoteWriteReceiver)
}

func setupServer(t *testing.T) {
t.Helper()

prwReceiver := setupMetricsReceiver(t)
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

assert.NoError(t, prwReceiver.Start(ctx, componenttest.NewNopHost()))
t.Cleanup(func() {
assert.NoError(t, prwReceiver.Shutdown(ctx), "Must not error shutting down")
})
}

func TestHandlePRWContentTypeNegotiation(t *testing.T) {
setupServer(t)

for _, tc := range []struct {
name string
contentType string
Expand Down Expand Up @@ -113,13 +98,16 @@ func TestHandlePRWContentTypeNegotiation(t *testing.T) {

var compressedBody []byte
snappy.Encode(compressedBody, pBuf.Bytes())
req, err := http.NewRequest(http.MethodPost, "http://localhost:9090/api/v1/write", bytes.NewBuffer(compressedBody))
assert.NoError(t, err)

req := httptest.NewRequest(http.MethodPost, "/api/v1/write", bytes.NewBuffer(compressedBody))

req.Header.Set("Content-Type", tc.contentType)
req.Header.Set("Content-Encoding", "snappy")
resp, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
w := httptest.NewRecorder()

prwReceiver := setupMetricsReceiver(t)
prwReceiver.handlePRW(w, req)
resp := w.Result()

assert.Equal(t, tc.expectedCode, resp.StatusCode)
if tc.expectedCode == http.StatusNoContent { // We went until the end
Expand Down

0 comments on commit 960d21c

Please sign in to comment.