Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/docker/packaging/docker/chainguar…
Browse files Browse the repository at this point in the history
…d/static-1c785f2
  • Loading branch information
kruskall authored Oct 29, 2024
2 parents ee39303 + 24d2222 commit 6a5ab61
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 18 deletions.
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ x-logging: &default-logging
services:
elasticsearch:
# TODO: replace with a pinned version such as 9.0.0-aaaaaaaa-SNAPSHOT
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.0-862b23c2-SNAPSHOT
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.0-0bb510c0-SNAPSHOT
ports:
- 9200:9200
healthcheck:
Expand Down Expand Up @@ -43,7 +43,7 @@ services:

kibana:
# TODO: replace with a pinned version such as 9.0.0-aaaaaaaa-SNAPSHOT
image: docker.elastic.co/kibana/kibana:9.0.0-862b23c2-SNAPSHOT
image: docker.elastic.co/kibana/kibana:9.0.0-0bb510c0-SNAPSHOT
ports:
- 5601:5601
healthcheck:
Expand All @@ -63,7 +63,7 @@ services:

metricbeat:
# TODO: replace with a pinned version such as 9.0.0-aaaaaaaa-SNAPSHOT
image: docker.elastic.co/beats/metricbeat:9.0.0-862b23c2-SNAPSHOT
image: docker.elastic.co/beats/metricbeat:9.0.0-0bb510c0-SNAPSHOT
environment:
ELASTICSEARCH_HOSTS: '["http://elasticsearch:9200"]'
ELASTICSEARCH_USERNAME: "${KIBANA_ES_USER:-admin}"
Expand Down
91 changes: 91 additions & 0 deletions internal/elasticsearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package elasticsearch

import (
"bytes"
"context"
"fmt"
"net/http"
Expand All @@ -30,6 +31,7 @@ import (

apmVersion "github.com/elastic/apm-server/internal/version"
esv8 "github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v8/esapi"
)

func TestClient(t *testing.T) {
Expand Down Expand Up @@ -86,3 +88,92 @@ func TestClientCustomUserAgent(t *testing.T) {
t.Fatal("timed out while waiting for request")
}
}

func esMockHandler(responder http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Elastic-Product", "Elasticsearch")

switch {
case r.Method == http.MethodPost && r.URL.Path == "/_bulk":
responder(w, r)
return
default:
http.Error(w, "unsupported request", 419) // Signal unexpected error
return
}
}
}

func TestClientRetryableStatuses(t *testing.T) {
tests := []struct {
name string
responseStatusCode int
expectedStatusCode int
expectedRequestCount int
}{
{
name: "retry 429 Too Many Requests",
responseStatusCode: http.StatusTooManyRequests,
expectedStatusCode: http.StatusOK,
expectedRequestCount: 2,
},
{
name: "retry 502 Bad Gateway",
responseStatusCode: http.StatusBadGateway,
expectedStatusCode: http.StatusBadGateway,
expectedRequestCount: 1,
},
{
name: "retry 503 Service Not Available",
responseStatusCode: http.StatusServiceUnavailable,
expectedStatusCode: http.StatusServiceUnavailable,
expectedRequestCount: 1,
},
{
name: "retry 504 Gateway Timeout",
responseStatusCode: http.StatusGatewayTimeout,
expectedStatusCode: http.StatusGatewayTimeout,
expectedRequestCount: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
maxRetries := 2
count := 0
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if count < maxRetries {
count += 1
http.Error(w, "", tt.responseStatusCode)
return
}

w.WriteHeader(http.StatusOK)
})

es := esMockHandler(handler)
srv := httptest.NewServer(&es)
defer srv.Close()

c := Config{
Username: "test",
Password: "foobar",
Backoff: BackoffConfig{
Init: 0,
Max: 0,
},
MaxRetries: maxRetries,
Hosts: []string{srv.URL},
}
client, err := NewClient(&c)
require.NoError(t, err)

var buf bytes.Buffer
var res *esapi.Response
res, err = client.Bulk(bytes.NewReader(buf.Bytes()))
require.NoError(t, err)
assert.Equal(t, tt.expectedStatusCode, res.StatusCode)
assert.Equal(t, tt.expectedRequestCount, count)
})
}
}
4 changes: 2 additions & 2 deletions systemtest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/tidwall/gjson v1.18.0
go.elastic.co/apm/v2 v2.6.2
go.elastic.co/fastjson v1.4.0
go.opentelemetry.io/collector/pdata v1.17.0
go.opentelemetry.io/collector/semconv v0.111.0
go.opentelemetry.io/collector/pdata v1.18.0
go.opentelemetry.io/collector/semconv v0.112.0
go.opentelemetry.io/otel v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.31.0
Expand Down
8 changes: 4 additions & 4 deletions systemtest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ go.elastic.co/apm/v2 v2.6.2 h1:VBplAxgbOgTv+Giw/FS91xJpHYw/q8fz/XKPvqC+7/o=
go.elastic.co/apm/v2 v2.6.2/go.mod h1:33rOXgtHwbgZcDgi6I/GtCSMZQqgxkHC0IQT3gudKvo=
go.elastic.co/fastjson v1.4.0 h1:a4BXUKXZHAzjVOPrqtEx2FDsIRBCMek01vCnrtyutWs=
go.elastic.co/fastjson v1.4.0/go.mod h1:ZD5um63l0/8TIdddZbL2znD83FAr2IckYa3KR7VcdNA=
go.opentelemetry.io/collector/pdata v1.17.0 h1:z8cjjT2FThAehWu5fbF48OnZyK5q8xd1UhC4XszDo0w=
go.opentelemetry.io/collector/pdata v1.17.0/go.mod h1:yZaQ9KZAm/qie96LTygRKxOXMq0/54h8OW7330ycuvQ=
go.opentelemetry.io/collector/semconv v0.111.0 h1:ELleMtLBzeZ3xhfhYPmFcLc0hJMqRxhOB0eY60WLivw=
go.opentelemetry.io/collector/semconv v0.111.0/go.mod h1:zCJ5njhWpejR+A40kiEoeFm1xq1uzyZwMnRNX6/D82A=
go.opentelemetry.io/collector/pdata v1.18.0 h1:/yg2rO2dxqDM2p6GutsMCxXN6sKlXwyIz/ZYyUPONBg=
go.opentelemetry.io/collector/pdata v1.18.0/go.mod h1:Ox1YVLe87cZDB/TL30i4SUz1cA5s6AM6SpFMfY61ICs=
go.opentelemetry.io/collector/semconv v0.112.0 h1:JPQyvZhlNLVSuVI+FScONaiFygB7h7NTZceUEKIQUEc=
go.opentelemetry.io/collector/semconv v0.112.0/go.mod h1:zCJ5njhWpejR+A40kiEoeFm1xq1uzyZwMnRNX6/D82A=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 h1:ZIg3ZT/aQ7AfKqdwp7ECpOK6vHqquXXuyTjIO8ZdmPs=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0/go.mod h1:DQAwmETtZV00skUwgD6+0U89g80NKsJE3DCKeLLPQMI=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
Expand Down
2 changes: 1 addition & 1 deletion testing/infra/k8s/base/stack/apm-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: apm-server
spec:
# TODO: replace with a pinned version such as 9.0.0-aaaaaaaa-SNAPSHOT
version: 9.0.0-862b23c2-SNAPSHOT
version: 9.0.0-0bb510c0-SNAPSHOT
count: 1
http:
tls:
Expand Down
2 changes: 1 addition & 1 deletion testing/infra/k8s/base/stack/elasticsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: elasticsearch
spec:
# TODO: replace with a pinned version such as 9.0.0-aaaaaaaa-SNAPSHOT
version: 9.0.0-862b23c2-SNAPSHOT
version: 9.0.0-0bb510c0-SNAPSHOT
auth:
fileRealm:
- secretName: elasticsearch-admin
Expand Down
2 changes: 1 addition & 1 deletion testing/infra/k8s/base/stack/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: kibana
spec:
# TODO: replace with a pinned version such as 9.0.0-aaaaaaaa-SNAPSHOT
version: 9.0.0-862b23c2-SNAPSHOT
version: 9.0.0-0bb510c0-SNAPSHOT
count: 1
elasticsearchRef:
name: elasticsearch
Expand Down
4 changes: 2 additions & 2 deletions tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/elastic/apm-tools v0.0.0-20230828065051-3f799314cc8b
github.com/elastic/go-licenser v0.4.2
github.com/elastic/gobench v0.0.0-20220608141032-f30bc57e329c
github.com/goreleaser/nfpm/v2 v2.40.0
github.com/goreleaser/nfpm/v2 v2.41.0
github.com/josephspurrier/goversioninfo v1.4.1
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c
github.com/terraform-docs/terraform-docs v0.19.0
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.10 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down
8 changes: 4 additions & 4 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ github.com/goreleaser/chglog v0.6.1 h1:NZKiX8l0FTQPRzBgKST7knvNZmZ04f7PEGkN2wInf
github.com/goreleaser/chglog v0.6.1/go.mod h1:Bnnfo07jMZkaAb0uRNASMZyOsX6ROW6X1qbXqN3guUo=
github.com/goreleaser/fileglob v1.3.0 h1:/X6J7U8lbDpQtBvGcwwPS6OpzkNVlVEsFUVRx9+k+7I=
github.com/goreleaser/fileglob v1.3.0/go.mod h1:Jx6BoXv3mbYkEzwm9THo7xbr5egkAraxkGorbJb4RxU=
github.com/goreleaser/nfpm/v2 v2.40.0 h1:M6WaaHeTCgNopUo9e8zgeHlOiN65LZAKqogzCJXBwYQ=
github.com/goreleaser/nfpm/v2 v2.40.0/go.mod h1:i9IfzvnHInDQohFs7iVHpWBoGaSDRp0+KG7KzNUXzns=
github.com/goreleaser/nfpm/v2 v2.41.0 h1:JyMzS/EwqaWbFs+7Z9oZ4Hkk4or00gUTqwm9Dgr8QYg=
github.com/goreleaser/nfpm/v2 v2.41.0/go.mod h1:VPc5kF5OgfA+BosV/A2aB+Vg34honjWvp0Vt8ogsSi0=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI=
Expand Down Expand Up @@ -172,8 +172,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down

0 comments on commit 6a5ab61

Please sign in to comment.