Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/prometheusremotewrite] flaky test #37563

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.extectedCode, resp.StatusCode)
if tc.extectedCode == http.StatusNoContent { // We went until the end
Expand Down
Loading