Skip to content

Commit

Permalink
[chore] add k8sclusterreceiver e2e test (open-telemetry#23386)
Browse files Browse the repository at this point in the history
Adds an e2e test for k8sclusterreceiver with a golden metrics file.
  • Loading branch information
atoulme authored Jun 15, 2023
1 parent 1bf2547 commit c7462f2
Show file tree
Hide file tree
Showing 19 changed files with 1,718 additions and 42 deletions.
50 changes: 46 additions & 4 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,45 @@ on:
pull_request:

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
cache: false
- name: Cache Go
id: go-cache
uses: actions/cache@v3
with:
path: |
~/go/bin
~/go/pkg/mod
key: go-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Install dependencies
if: steps.go-cache.outputs.cache-hit != 'true'
run: make -j2 gomoddownload
- name: Build Docker Image
run: |
make docker-otelcontribcol
- name: export image to tar
run: |
docker save otelcontribcol:latest > /tmp/otelcontribcol.tar
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: otelcontribcol
path: /tmp/otelcontribcol.tar
kubernetes-test:
env:
KUBECONFIG: /tmp/kube-config-otelcol-e2e-testing
strategy:
matrix:
k8s-version: ["v1.26.0", "v1.25.3", "v1.24.7", "v1.23.13"]
runs-on: ubuntu-latest
needs: docker-build
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
Expand All @@ -33,19 +65,29 @@ jobs:
- name: Install dependencies
if: steps.go-cache.outputs.cache-hit != 'true'
run: make -j2 gomoddownload
- name: Build Docker Image
run: |
make docker-otelcontribcol
- name: Create kind cluster
uses: helm/kind-action@v1.7.0
with:
node_image: kindest/node:${{ matrix.k8s-version }}
kubectl_version: ${{ matrix.k8s-version }}
cluster_name: kind
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: otelcontribcol
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/otelcontribcol.tar
- name: Kind load image
run: |
kind load docker-image otelcontribcol:latest --name kind
- name: run e2e tests
- name: run k8sclusterreceiver e2e tests
run: |
cd receiver/k8sclusterreceiver
go test -v --tags=e2e
- name: run k8sattributesprocessor e2e tests
run: |
cd processor/k8sattributesprocessor
go test -v --tags=e2e
8 changes: 4 additions & 4 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,13 @@ require (
go.uber.org/goleak v1.2.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/oauth2 v0.9.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.1 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand Down
13 changes: 8 additions & 5 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,13 @@ require (
go.uber.org/goleak v1.2.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/oauth2 v0.9.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.1 // indirect
Expand Down
13 changes: 8 additions & 5 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,14 @@ require (
go.uber.org/goleak v1.2.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/oauth2 v0.9.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.1 // indirect
Expand Down
13 changes: 8 additions & 5 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/pdatatest/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ func MaskResourceAttributeValue(res pcommon.Resource, attr string) {
}
}

func ChangeResourceAttributeValue(res pcommon.Resource, attr string, changeFn func(string) string) {
if _, ok := res.Attributes().Get(attr); ok {
if v, ok := res.Attributes().Get(attr); ok {
res.Attributes().PutStr(attr, changeFn(v.Str()))
}
}
}

// AddErrPrefix adds a prefix to every multierr error.
func AddErrPrefix(prefix string, in error) error {
var out error
Expand Down
14 changes: 14 additions & 0 deletions pkg/pdatatest/pmetrictest/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ func maskMetricsResourceAttributeValue(metrics pmetric.Metrics, attributeName st
}
}

func ChangeResourceAttributeValue(attributeName string, changeFn func(string) string) CompareMetricsOption {
return compareMetricsOptionFunc(func(expected, actual pmetric.Metrics) {
changeMetricsResourceAttributeValue(expected, attributeName, changeFn)
changeMetricsResourceAttributeValue(actual, attributeName, changeFn)
})
}

func changeMetricsResourceAttributeValue(metrics pmetric.Metrics, attributeName string, changeFn func(string) string) {
rms := metrics.ResourceMetrics()
for i := 0; i < rms.Len(); i++ {
internal.ChangeResourceAttributeValue(rms.At(i).Resource(), attributeName, changeFn)
}
}

// IgnoreSubsequentDataPoints is a CompareMetricsOption that ignores data points after the first.
func IgnoreSubsequentDataPoints(metricNames ...string) CompareMetricsOption {
return compareMetricsOptionFunc(func(expected, actual pmetric.Metrics) {
Expand Down
Loading

0 comments on commit c7462f2

Please sign in to comment.