From bcb391942d972db052a6d612938249e529abe373 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:04:10 -0400 Subject: [PATCH 1/8] Bump golang from 1.22.5-alpine to 1.22.6-alpine in /docker/debug (#5816) Bumps golang from 1.22.5-alpine to 1.22.6-alpine. [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=golang&package-manager=docker&previous-version=1.22.5-alpine&new-version=1.22.6-alpine)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docker/debug/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/debug/Dockerfile b/docker/debug/Dockerfile index 31cf0351e9b..8413e09c72b 100644 --- a/docker/debug/Dockerfile +++ b/docker/debug/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22.5-alpine AS build +FROM golang:1.22.6-alpine AS build ARG TARGETARCH ENV GOPATH /go RUN apk add --update --no-cache ca-certificates make git build-base mailcap @@ -10,7 +10,7 @@ RUN if [[ "$TARGETARCH" == "s390x" || "$TARGETARCH" == "ppc64le" ]] ; then \ go install github.com/go-delve/delve/cmd/dlv@latest; \ fi -FROM golang:1.22.5-alpine +FROM golang:1.22.6-alpine COPY --from=build /go/bin/dlv /go/bin/dlv COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=build /etc/mime.types /etc/mime.types From aeb457a492cec84208ee9abc9bc20a8c494cf882 Mon Sep 17 00:00:00 2001 From: Nabil Salah Date: Thu, 8 Aug 2024 21:22:37 +0300 Subject: [PATCH 2/8] Added unit tests in pkg/es/config (#5806) ## Which problem is this PR solving? partially fixes: #5068 ## Description of the changes - This commit adds tests for the `pkg/es/config` package. ## How was this change tested? - `make test` ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` Signed-off-by: nabil salah Co-authored-by: Yuri Shkuro --- jaeger-ui | 2 +- pkg/es/config/config_test.go | 625 +++++++++++++++++++++++++++++++++++ 2 files changed, 626 insertions(+), 1 deletion(-) create mode 100644 pkg/es/config/config_test.go diff --git a/jaeger-ui b/jaeger-ui index 3b093f81dec..1704a9a66ae 160000 --- a/jaeger-ui +++ b/jaeger-ui @@ -1 +1 @@ -Subproject commit 3b093f81dec59c6bb04daad96b1b77bd03a29e4a +Subproject commit 1704a9a66ae780ec6bb2f524116176aa9c8a23f8 diff --git a/pkg/es/config/config_test.go b/pkg/es/config/config_test.go new file mode 100644 index 00000000000..285dead5291 --- /dev/null +++ b/pkg/es/config/config_test.go @@ -0,0 +1,625 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package config + +import ( + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "testing" + "time" + + "github.com/stretchr/testify/require" + "go.uber.org/zap" + + "github.com/jaegertracing/jaeger/pkg/config/tlscfg" + "github.com/jaegertracing/jaeger/pkg/metrics" +) + +var mockEsServerResponseWithVersion0 = []byte(` +{ + "Version": { + "Number": "0" + } +} +`) + +var mockEsServerResponseWithVersion1 = []byte(` +{ + "tagline": "OpenSearch", + "Version": { + "Number": "1" + } +} +`) + +var mockEsServerResponseWithVersion2 = []byte(` +{ + "tagline": "OpenSearch", + "Version": { + "Number": "2" + } +} +`) + +var mockEsServerResponseWithVersion8 = []byte(` +{ + "tagline": "OpenSearch", + "Version": { + "Number": "9" + } +} +`) + +func copyToTempFile(t *testing.T, pattern string, filename string) (file *os.File) { + tempDir := t.TempDir() + tempFilePath := tempDir + "/" + pattern + tempFile, err := os.Create(tempFilePath) + require.NoError(t, err) + data, err := os.ReadFile(filename) + require.NoError(t, err) + + _, err = tempFile.Write(data) + require.NoError(t, err) + require.NoError(t, tempFile.Close()) + + return tempFile +} + +func TestNewClient(t *testing.T) { + const ( + pwd1 = "password" + token = "token" + serverCert = "../../config/tlscfg/testdata/example-server-cert.pem" + ) + pwdFile := filepath.Join(t.TempDir(), "pwd") + require.NoError(t, os.WriteFile(pwdFile, []byte(pwd1), 0o600)) + pwdtokenFile := filepath.Join(t.TempDir(), "token") + require.NoError(t, os.WriteFile(pwdtokenFile, []byte(token), 0o600)) + // copy certs to temp so we can modify them + certFilePath := copyToTempFile(t, "cert.crt", serverCert) + + testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + require.Equal(t, http.MethodGet, req.Method) + res.WriteHeader(http.StatusOK) + res.Write(mockEsServerResponseWithVersion0) + })) + defer testServer.Close() + testServer1 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + require.Equal(t, http.MethodGet, req.Method) + res.WriteHeader(http.StatusOK) + res.Write(mockEsServerResponseWithVersion1) + })) + defer testServer1.Close() + testServer2 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + require.Equal(t, http.MethodGet, req.Method) + res.WriteHeader(http.StatusOK) + res.Write(mockEsServerResponseWithVersion2) + })) + defer testServer2.Close() + testServer8 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + require.Equal(t, http.MethodGet, req.Method) + res.WriteHeader(http.StatusOK) + res.Write(mockEsServerResponseWithVersion8) + })) + defer testServer8.Close() + tests := []struct { + name string + config *Configuration + expectedError bool + }{ + { + name: "success with valid configuration", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + Version: 8, + }, + expectedError: false, + }, + { + name: "success with valid configuration and tls enabled", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + Version: 8, + TLS: tlscfg.Options{Enabled: true}, + }, + expectedError: false, + }, + { + name: "success with valid configuration and reading token and certicate from file", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + Version: 1, + TLS: tlscfg.Options{Enabled: false, CAPath: certFilePath.Name()}, + TokenFilePath: pwdtokenFile, + }, + expectedError: false, + }, + { + name: "succes with invalid configuration of version higher than 8", + config: &Configuration{ + Servers: []string{testServer8.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + Version: 9, + }, + expectedError: false, + }, + { + name: "success with valid configuration with version 1", + config: &Configuration{ + Servers: []string{testServer1.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + { + name: "success with valid configuration with version 2", + config: &Configuration{ + Servers: []string{testServer2.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + { + name: "success with valid configuration password from file", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "", + LogLevel: "debug", + Username: "user", + PasswordFilePath: pwdFile, + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + { + name: "fali with configuration password and password from file are set", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: pwdFile, + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: true, + }, + { + name: "fail with missing server", + config: &Configuration{ + Servers: []string{}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: true, + }, + { + name: "fail with invalid configuration invalid loglevel", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "invalid", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: true, + }, + { + name: "fail with invalid configuration invalid bulkworkers number", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "invalid", + Username: "user", + PasswordFilePath: "", + BulkWorkers: 0, + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: true, + }, + { + name: "success with valid configuration and info log level", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "info", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + { + name: "success with valid configuration and error log level", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "error", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + logger := zap.NewNop() + metricsFactory := metrics.NullFactory + config := test.config + client, err := NewClient(config, logger, metricsFactory) + if test.expectedError { + require.Error(t, err) + require.Nil(t, client) + } else { + require.NoError(t, err) + require.NotNil(t, client) + } + }) + } +} + +func TestApplyDefaults(t *testing.T) { + source := &Configuration{ + RemoteReadClusters: []string{"cluster1", "cluster2"}, + Username: "sourceUser", + Password: "sourcePass", + Sniffer: true, + MaxSpanAge: 100, + AdaptiveSamplingLookback: 50, + NumShards: 5, + NumReplicas: 1, + PrioritySpanTemplate: 10, + PriorityServiceTemplate: 20, + PriorityDependenciesTemplate: 30, + BulkSize: 1000, + BulkWorkers: 10, + BulkActions: 100, + BulkFlushInterval: 30, + SnifferTLSEnabled: true, + Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, + MaxDocCount: 10000, + LogLevel: "info", + SendGetBodyAs: "json", + } + + tests := []struct { + name string + target *Configuration + expected *Configuration + }{ + { + name: "All Defaults Applied except PriorityDependenciesTemplate", + target: &Configuration{ + PriorityDependenciesTemplate: 30, + }, // All fields are empty + expected: source, + }, + { + name: "Some Defaults Applied", + target: &Configuration{ + RemoteReadClusters: []string{"customCluster"}, + Username: "customUser", + PrioritySpanTemplate: 10, + PriorityServiceTemplate: 20, + PriorityDependenciesTemplate: 30, + // Other fields left default + }, + expected: &Configuration{ + RemoteReadClusters: []string{"customCluster"}, + Username: "customUser", + Password: "sourcePass", + Sniffer: true, + SnifferTLSEnabled: true, + MaxSpanAge: 100, + AdaptiveSamplingLookback: 50, + NumShards: 5, + NumReplicas: 1, + PrioritySpanTemplate: 10, + PriorityServiceTemplate: 20, + PriorityDependenciesTemplate: 30, + BulkSize: 1000, + BulkWorkers: 10, + BulkActions: 100, + BulkFlushInterval: 30, + Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, + MaxDocCount: 10000, + LogLevel: "info", + SendGetBodyAs: "json", + }, + }, + { + name: "No Defaults Applied", + target: &Configuration{ + RemoteReadClusters: []string{"cluster1", "cluster2"}, + Username: "sourceUser", + Password: "sourcePass", + Sniffer: true, + MaxSpanAge: 100, + AdaptiveSamplingLookback: 50, + NumShards: 5, + NumReplicas: 1, + PrioritySpanTemplate: 10, + PriorityServiceTemplate: 20, + PriorityDependenciesTemplate: 30, + BulkSize: 1000, + BulkWorkers: 10, + BulkActions: 100, + BulkFlushInterval: 30, + SnifferTLSEnabled: true, + Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, + MaxDocCount: 10000, + LogLevel: "info", + SendGetBodyAs: "json", + }, + expected: source, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + test.target.ApplyDefaults(source) + require.Equal(t, test.expected, test.target) + }) + } +} + +func TestTagKeysAsFields(t *testing.T) { + const ( + pwd1 = "tag1\ntag2" + ) + pwdFile := filepath.Join(t.TempDir(), "pwd") + require.NoError(t, os.WriteFile(pwdFile, []byte(pwd1), 0o600)) + + tests := []struct { + name string + config *Configuration + expectedTags []string + expectError bool + }{ + { + name: "File with tags", + config: &Configuration{ + Tags: TagsAsFields{ + File: pwdFile, + Include: "", + }, + }, + expectedTags: []string{"tag1", "tag2"}, + expectError: false, + }, + { + name: "include with tags", + config: &Configuration{ + Tags: TagsAsFields{ + File: "", + Include: "cmdtag1,cmdtag2", + }, + }, + expectedTags: []string{"cmdtag1", "cmdtag2"}, + expectError: false, + }, + { + name: "File and include with tags", + config: &Configuration{ + Tags: TagsAsFields{ + File: pwdFile, + Include: "cmdtag1,cmdtag2", + }, + }, + expectedTags: []string{"tag1", "tag2", "cmdtag1", "cmdtag2"}, + expectError: false, + }, + { + name: "File read error", + config: &Configuration{ + Tags: TagsAsFields{ + File: "/invalid/path/to/file.txt", + Include: "", + }, + }, + expectedTags: nil, + expectError: true, + }, + { + name: "Empty file and params", + config: &Configuration{ + Tags: TagsAsFields{ + File: "", + Include: "", + }, + }, + expectedTags: nil, + expectError: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + tags, err := test.config.TagKeysAsFields() + + if test.expectError { + require.Error(t, err) + require.Nil(t, tags) + } else { + require.NoError(t, err) + require.ElementsMatch(t, test.expectedTags, tags) + } + }) + } +} + +func TestGetIndexRolloverFrequencySpansDuration(t *testing.T) { + tests := []struct { + name string + indexFrequency string + expected time.Duration + }{ + { + name: "hourly jaeger-span", + indexFrequency: "hour", + expected: -1 * time.Hour, + }, + { + name: "daily jaeger-span", + indexFrequency: "daily", + expected: -24 * time.Hour, + }, + { + name: "empty jaeger-span", + indexFrequency: "", + expected: -24 * time.Hour, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + c := &Configuration{IndexRolloverFrequencySpans: test.indexFrequency} + got := c.GetIndexRolloverFrequencySpansDuration() + require.Equal(t, test.expected, got) + }) + } +} + +func TestGetIndexRolloverFrequencyServicesDuration(t *testing.T) { + tests := []struct { + name string + indexFrequency string + expected time.Duration + }{ + { + name: "hourly jaeger-service", + indexFrequency: "hour", + expected: -1 * time.Hour, + }, + { + name: "daily jaeger-service", + indexFrequency: "daily", + expected: -24 * time.Hour, + }, + { + name: "empty jaeger-service", + indexFrequency: "", + expected: -24 * time.Hour, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + c := &Configuration{IndexRolloverFrequencyServices: test.indexFrequency} + got := c.GetIndexRolloverFrequencyServicesDuration() + require.Equal(t, test.expected, got) + }) + } +} + +func TestGetIndexRolloverFrequencySamplingDuration(t *testing.T) { + tests := []struct { + name string + indexFrequency string + expected time.Duration + }{ + { + name: "hourly jaeger-sampling", + indexFrequency: "hour", + expected: -1 * time.Hour, + }, + { + name: "daily jaeger-sampling", + indexFrequency: "daily", + expected: -24 * time.Hour, + }, + { + name: "empty jaeger-sampling", + indexFrequency: "", + expected: -24 * time.Hour, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + c := &Configuration{IndexRolloverFrequencySampling: test.indexFrequency} + got := c.GetIndexRolloverFrequencySamplingDuration() + require.Equal(t, test.expected, got) + }) + } +} + +func TestValidate(t *testing.T) { + tests := []struct { + name string + config *Configuration + expectedError bool + }{ + { + name: "All valid input are set", + config: &Configuration{ + Servers: []string{"localhost:8000/dummyserver"}, + }, + expectedError: false, + }, + { + name: "no valid input are set", + config: &Configuration{}, + expectedError: true, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.config.Validate() + if test.expectedError { + require.Error(t, got) + } else { + require.NoError(t, got) + } + }) + } +} From 0da1609a1755a5a40363208e71adbc5b45f24e8b Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Thu, 8 Aug 2024 14:24:30 -0400 Subject: [PATCH 3/8] Revert "Added unit tests in pkg/es/config (#5806)" This reverts commit aeb457a492cec84208ee9abc9bc20a8c494cf882. The PR incorrectly include UI submodule changes. Signed-off-by: Yuri Shkuro --- jaeger-ui | 2 +- pkg/es/config/config_test.go | 625 ----------------------------------- 2 files changed, 1 insertion(+), 626 deletions(-) delete mode 100644 pkg/es/config/config_test.go diff --git a/jaeger-ui b/jaeger-ui index 1704a9a66ae..3b093f81dec 160000 --- a/jaeger-ui +++ b/jaeger-ui @@ -1 +1 @@ -Subproject commit 1704a9a66ae780ec6bb2f524116176aa9c8a23f8 +Subproject commit 3b093f81dec59c6bb04daad96b1b77bd03a29e4a diff --git a/pkg/es/config/config_test.go b/pkg/es/config/config_test.go deleted file mode 100644 index 285dead5291..00000000000 --- a/pkg/es/config/config_test.go +++ /dev/null @@ -1,625 +0,0 @@ -// Copyright (c) 2024 The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 - -package config - -import ( - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "testing" - "time" - - "github.com/stretchr/testify/require" - "go.uber.org/zap" - - "github.com/jaegertracing/jaeger/pkg/config/tlscfg" - "github.com/jaegertracing/jaeger/pkg/metrics" -) - -var mockEsServerResponseWithVersion0 = []byte(` -{ - "Version": { - "Number": "0" - } -} -`) - -var mockEsServerResponseWithVersion1 = []byte(` -{ - "tagline": "OpenSearch", - "Version": { - "Number": "1" - } -} -`) - -var mockEsServerResponseWithVersion2 = []byte(` -{ - "tagline": "OpenSearch", - "Version": { - "Number": "2" - } -} -`) - -var mockEsServerResponseWithVersion8 = []byte(` -{ - "tagline": "OpenSearch", - "Version": { - "Number": "9" - } -} -`) - -func copyToTempFile(t *testing.T, pattern string, filename string) (file *os.File) { - tempDir := t.TempDir() - tempFilePath := tempDir + "/" + pattern - tempFile, err := os.Create(tempFilePath) - require.NoError(t, err) - data, err := os.ReadFile(filename) - require.NoError(t, err) - - _, err = tempFile.Write(data) - require.NoError(t, err) - require.NoError(t, tempFile.Close()) - - return tempFile -} - -func TestNewClient(t *testing.T) { - const ( - pwd1 = "password" - token = "token" - serverCert = "../../config/tlscfg/testdata/example-server-cert.pem" - ) - pwdFile := filepath.Join(t.TempDir(), "pwd") - require.NoError(t, os.WriteFile(pwdFile, []byte(pwd1), 0o600)) - pwdtokenFile := filepath.Join(t.TempDir(), "token") - require.NoError(t, os.WriteFile(pwdtokenFile, []byte(token), 0o600)) - // copy certs to temp so we can modify them - certFilePath := copyToTempFile(t, "cert.crt", serverCert) - - testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - require.Equal(t, http.MethodGet, req.Method) - res.WriteHeader(http.StatusOK) - res.Write(mockEsServerResponseWithVersion0) - })) - defer testServer.Close() - testServer1 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - require.Equal(t, http.MethodGet, req.Method) - res.WriteHeader(http.StatusOK) - res.Write(mockEsServerResponseWithVersion1) - })) - defer testServer1.Close() - testServer2 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - require.Equal(t, http.MethodGet, req.Method) - res.WriteHeader(http.StatusOK) - res.Write(mockEsServerResponseWithVersion2) - })) - defer testServer2.Close() - testServer8 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - require.Equal(t, http.MethodGet, req.Method) - res.WriteHeader(http.StatusOK) - res.Write(mockEsServerResponseWithVersion8) - })) - defer testServer8.Close() - tests := []struct { - name string - config *Configuration - expectedError bool - }{ - { - name: "success with valid configuration", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "debug", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - Version: 8, - }, - expectedError: false, - }, - { - name: "success with valid configuration and tls enabled", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "debug", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - Version: 8, - TLS: tlscfg.Options{Enabled: true}, - }, - expectedError: false, - }, - { - name: "success with valid configuration and reading token and certicate from file", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "debug", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - Version: 1, - TLS: tlscfg.Options{Enabled: false, CAPath: certFilePath.Name()}, - TokenFilePath: pwdtokenFile, - }, - expectedError: false, - }, - { - name: "succes with invalid configuration of version higher than 8", - config: &Configuration{ - Servers: []string{testServer8.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "debug", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - Version: 9, - }, - expectedError: false, - }, - { - name: "success with valid configuration with version 1", - config: &Configuration{ - Servers: []string{testServer1.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "debug", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: false, - }, - { - name: "success with valid configuration with version 2", - config: &Configuration{ - Servers: []string{testServer2.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "debug", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: false, - }, - { - name: "success with valid configuration password from file", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "", - LogLevel: "debug", - Username: "user", - PasswordFilePath: pwdFile, - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: false, - }, - { - name: "fali with configuration password and password from file are set", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "debug", - Username: "user", - PasswordFilePath: pwdFile, - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: true, - }, - { - name: "fail with missing server", - config: &Configuration{ - Servers: []string{}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "debug", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: true, - }, - { - name: "fail with invalid configuration invalid loglevel", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "invalid", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: true, - }, - { - name: "fail with invalid configuration invalid bulkworkers number", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "invalid", - Username: "user", - PasswordFilePath: "", - BulkWorkers: 0, - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: true, - }, - { - name: "success with valid configuration and info log level", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "info", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: false, - }, - { - name: "success with valid configuration and error log level", - config: &Configuration{ - Servers: []string{testServer.URL}, - AllowTokenFromContext: true, - Password: "secret", - LogLevel: "error", - Username: "user", - PasswordFilePath: "", - BulkSize: -1, // disable bulk; we want immediate flush - }, - expectedError: false, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - logger := zap.NewNop() - metricsFactory := metrics.NullFactory - config := test.config - client, err := NewClient(config, logger, metricsFactory) - if test.expectedError { - require.Error(t, err) - require.Nil(t, client) - } else { - require.NoError(t, err) - require.NotNil(t, client) - } - }) - } -} - -func TestApplyDefaults(t *testing.T) { - source := &Configuration{ - RemoteReadClusters: []string{"cluster1", "cluster2"}, - Username: "sourceUser", - Password: "sourcePass", - Sniffer: true, - MaxSpanAge: 100, - AdaptiveSamplingLookback: 50, - NumShards: 5, - NumReplicas: 1, - PrioritySpanTemplate: 10, - PriorityServiceTemplate: 20, - PriorityDependenciesTemplate: 30, - BulkSize: 1000, - BulkWorkers: 10, - BulkActions: 100, - BulkFlushInterval: 30, - SnifferTLSEnabled: true, - Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, - MaxDocCount: 10000, - LogLevel: "info", - SendGetBodyAs: "json", - } - - tests := []struct { - name string - target *Configuration - expected *Configuration - }{ - { - name: "All Defaults Applied except PriorityDependenciesTemplate", - target: &Configuration{ - PriorityDependenciesTemplate: 30, - }, // All fields are empty - expected: source, - }, - { - name: "Some Defaults Applied", - target: &Configuration{ - RemoteReadClusters: []string{"customCluster"}, - Username: "customUser", - PrioritySpanTemplate: 10, - PriorityServiceTemplate: 20, - PriorityDependenciesTemplate: 30, - // Other fields left default - }, - expected: &Configuration{ - RemoteReadClusters: []string{"customCluster"}, - Username: "customUser", - Password: "sourcePass", - Sniffer: true, - SnifferTLSEnabled: true, - MaxSpanAge: 100, - AdaptiveSamplingLookback: 50, - NumShards: 5, - NumReplicas: 1, - PrioritySpanTemplate: 10, - PriorityServiceTemplate: 20, - PriorityDependenciesTemplate: 30, - BulkSize: 1000, - BulkWorkers: 10, - BulkActions: 100, - BulkFlushInterval: 30, - Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, - MaxDocCount: 10000, - LogLevel: "info", - SendGetBodyAs: "json", - }, - }, - { - name: "No Defaults Applied", - target: &Configuration{ - RemoteReadClusters: []string{"cluster1", "cluster2"}, - Username: "sourceUser", - Password: "sourcePass", - Sniffer: true, - MaxSpanAge: 100, - AdaptiveSamplingLookback: 50, - NumShards: 5, - NumReplicas: 1, - PrioritySpanTemplate: 10, - PriorityServiceTemplate: 20, - PriorityDependenciesTemplate: 30, - BulkSize: 1000, - BulkWorkers: 10, - BulkActions: 100, - BulkFlushInterval: 30, - SnifferTLSEnabled: true, - Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, - MaxDocCount: 10000, - LogLevel: "info", - SendGetBodyAs: "json", - }, - expected: source, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - test.target.ApplyDefaults(source) - require.Equal(t, test.expected, test.target) - }) - } -} - -func TestTagKeysAsFields(t *testing.T) { - const ( - pwd1 = "tag1\ntag2" - ) - pwdFile := filepath.Join(t.TempDir(), "pwd") - require.NoError(t, os.WriteFile(pwdFile, []byte(pwd1), 0o600)) - - tests := []struct { - name string - config *Configuration - expectedTags []string - expectError bool - }{ - { - name: "File with tags", - config: &Configuration{ - Tags: TagsAsFields{ - File: pwdFile, - Include: "", - }, - }, - expectedTags: []string{"tag1", "tag2"}, - expectError: false, - }, - { - name: "include with tags", - config: &Configuration{ - Tags: TagsAsFields{ - File: "", - Include: "cmdtag1,cmdtag2", - }, - }, - expectedTags: []string{"cmdtag1", "cmdtag2"}, - expectError: false, - }, - { - name: "File and include with tags", - config: &Configuration{ - Tags: TagsAsFields{ - File: pwdFile, - Include: "cmdtag1,cmdtag2", - }, - }, - expectedTags: []string{"tag1", "tag2", "cmdtag1", "cmdtag2"}, - expectError: false, - }, - { - name: "File read error", - config: &Configuration{ - Tags: TagsAsFields{ - File: "/invalid/path/to/file.txt", - Include: "", - }, - }, - expectedTags: nil, - expectError: true, - }, - { - name: "Empty file and params", - config: &Configuration{ - Tags: TagsAsFields{ - File: "", - Include: "", - }, - }, - expectedTags: nil, - expectError: false, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - tags, err := test.config.TagKeysAsFields() - - if test.expectError { - require.Error(t, err) - require.Nil(t, tags) - } else { - require.NoError(t, err) - require.ElementsMatch(t, test.expectedTags, tags) - } - }) - } -} - -func TestGetIndexRolloverFrequencySpansDuration(t *testing.T) { - tests := []struct { - name string - indexFrequency string - expected time.Duration - }{ - { - name: "hourly jaeger-span", - indexFrequency: "hour", - expected: -1 * time.Hour, - }, - { - name: "daily jaeger-span", - indexFrequency: "daily", - expected: -24 * time.Hour, - }, - { - name: "empty jaeger-span", - indexFrequency: "", - expected: -24 * time.Hour, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - c := &Configuration{IndexRolloverFrequencySpans: test.indexFrequency} - got := c.GetIndexRolloverFrequencySpansDuration() - require.Equal(t, test.expected, got) - }) - } -} - -func TestGetIndexRolloverFrequencyServicesDuration(t *testing.T) { - tests := []struct { - name string - indexFrequency string - expected time.Duration - }{ - { - name: "hourly jaeger-service", - indexFrequency: "hour", - expected: -1 * time.Hour, - }, - { - name: "daily jaeger-service", - indexFrequency: "daily", - expected: -24 * time.Hour, - }, - { - name: "empty jaeger-service", - indexFrequency: "", - expected: -24 * time.Hour, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - c := &Configuration{IndexRolloverFrequencyServices: test.indexFrequency} - got := c.GetIndexRolloverFrequencyServicesDuration() - require.Equal(t, test.expected, got) - }) - } -} - -func TestGetIndexRolloverFrequencySamplingDuration(t *testing.T) { - tests := []struct { - name string - indexFrequency string - expected time.Duration - }{ - { - name: "hourly jaeger-sampling", - indexFrequency: "hour", - expected: -1 * time.Hour, - }, - { - name: "daily jaeger-sampling", - indexFrequency: "daily", - expected: -24 * time.Hour, - }, - { - name: "empty jaeger-sampling", - indexFrequency: "", - expected: -24 * time.Hour, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - c := &Configuration{IndexRolloverFrequencySampling: test.indexFrequency} - got := c.GetIndexRolloverFrequencySamplingDuration() - require.Equal(t, test.expected, got) - }) - } -} - -func TestValidate(t *testing.T) { - tests := []struct { - name string - config *Configuration - expectedError bool - }{ - { - name: "All valid input are set", - config: &Configuration{ - Servers: []string{"localhost:8000/dummyserver"}, - }, - expectedError: false, - }, - { - name: "no valid input are set", - config: &Configuration{}, - expectedError: true, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.config.Validate() - if test.expectedError { - require.Error(t, got) - } else { - require.NoError(t, got) - } - }) - } -} From 4220d62cf3e2f18356c8504666ff43a1d838c241 Mon Sep 17 00:00:00 2001 From: Jonah Kowall Date: Thu, 8 Aug 2024 16:03:33 -0400 Subject: [PATCH 4/8] Clarify release docs slightly (#5809) Just improving the docs a bit to make sure the release manager does the Jaeger UI before the rest of the directions. Signed-off-by: Jonah Kowall --- RELEASE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index ebf2f3353db..daf1a6688d1 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -5,7 +5,8 @@ * A curated list of notable changes and links to PRs. Do not simply dump git log, select the changes that affect the users. To obtain the list of all changes run `make changelog` or use `scripts/release-notes.py`. * The section can be split into sub-section if necessary, e.g. UI Changes, Backend Changes, Bug Fixes, etc. - * If the jaeger-ui submodule has changes cut a new release and also upgrade the submodule versions then commit, for example: + * If the jaeger-ui submodule has changes cut a new release + * Then upgrade the submodule versions and finally commit. For example: ``` git submodule init git submodule update From f250716cc0a1131dba46986ac4455eb43c364a15 Mon Sep 17 00:00:00 2001 From: Nabil Salah Date: Fri, 9 Aug 2024 00:52:34 +0300 Subject: [PATCH 5/8] Added unit tests in pkg/es/config (#5819) ## Which problem is this PR solving? Part of: #5068 ## Description of the changes - This commit adds tests for the `pkg/es/config` package. ## How was this change tested? - `make test` ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` Signed-off-by: nabil salah --- pkg/es/config/.nocover | 1 - pkg/es/config/config_test.go | 636 +++++++++++++++++++++++++++++++++++ 2 files changed, 636 insertions(+), 1 deletion(-) delete mode 100644 pkg/es/config/.nocover create mode 100644 pkg/es/config/config_test.go diff --git a/pkg/es/config/.nocover b/pkg/es/config/.nocover deleted file mode 100644 index 517b145dea2..00000000000 --- a/pkg/es/config/.nocover +++ /dev/null @@ -1 +0,0 @@ -requires connection to Elasticsearch diff --git a/pkg/es/config/config_test.go b/pkg/es/config/config_test.go new file mode 100644 index 00000000000..7ba124bfd9a --- /dev/null +++ b/pkg/es/config/config_test.go @@ -0,0 +1,636 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package config + +import ( + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "testing" + "time" + + "github.com/stretchr/testify/require" + "go.uber.org/zap" + + "github.com/jaegertracing/jaeger/pkg/config/tlscfg" + "github.com/jaegertracing/jaeger/pkg/metrics" + "github.com/jaegertracing/jaeger/pkg/testutils" +) + +var mockEsServerResponseWithVersion0 = []byte(` +{ + "Version": { + "Number": "0" + } +} +`) + +var mockEsServerResponseWithVersion1 = []byte(` +{ + "tagline": "OpenSearch", + "Version": { + "Number": "1" + } +} +`) + +var mockEsServerResponseWithVersion2 = []byte(` +{ + "tagline": "OpenSearch", + "Version": { + "Number": "2" + } +} +`) + +var mockEsServerResponseWithVersion8 = []byte(` +{ + "tagline": "OpenSearch", + "Version": { + "Number": "9" + } +} +`) + +func copyToTempFile(t *testing.T, pattern string, filename string) (file *os.File) { + tempDir := t.TempDir() + tempFilePath := tempDir + "/" + pattern + tempFile, err := os.Create(tempFilePath) + require.NoError(t, err) + data, err := os.ReadFile(filename) + + require.NoError(t, err) + + _, err = tempFile.Write(data) + require.NoError(t, err) + require.NoError(t, tempFile.Close()) + + return tempFile +} + +func TestNewClient(t *testing.T) { + const ( + pwd1 = "password" + token = "token" + serverCert = "../../config/tlscfg/testdata/example-server-cert.pem" + ) + pwdFile := filepath.Join(t.TempDir(), "pwd") + require.NoError(t, os.WriteFile(pwdFile, []byte(pwd1), 0o600)) + pwdtokenFile := filepath.Join(t.TempDir(), "token") + require.NoError(t, os.WriteFile(pwdtokenFile, []byte(token), 0o600)) + // copy certs to temp so we can modify them + certFilePath := copyToTempFile(t, "cert.crt", serverCert) + defer certFilePath.Close() + + testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + require.Equal(t, http.MethodGet, req.Method) + res.WriteHeader(http.StatusOK) + res.Write(mockEsServerResponseWithVersion0) + })) + defer testServer.Close() + testServer1 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + require.Equal(t, http.MethodGet, req.Method) + res.WriteHeader(http.StatusOK) + res.Write(mockEsServerResponseWithVersion1) + })) + defer testServer1.Close() + testServer2 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + require.Equal(t, http.MethodGet, req.Method) + res.WriteHeader(http.StatusOK) + res.Write(mockEsServerResponseWithVersion2) + })) + defer testServer2.Close() + testServer8 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + require.Equal(t, http.MethodGet, req.Method) + res.WriteHeader(http.StatusOK) + res.Write(mockEsServerResponseWithVersion8) + })) + defer testServer8.Close() + tests := []struct { + name string + config *Configuration + expectedError bool + }{ + { + name: "success with valid configuration", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + Version: 8, + }, + expectedError: false, + }, + { + name: "success with valid configuration and tls enabled", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + Version: 0, + TLS: tlscfg.Options{Enabled: true}, + }, + expectedError: false, + }, + { + name: "success with valid configuration and reading token and certicate from file", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + Version: 0, + TLS: tlscfg.Options{Enabled: false, CAPath: certFilePath.Name()}, + TokenFilePath: pwdtokenFile, + }, + expectedError: false, + }, + { + name: "succes with invalid configuration of version higher than 8", + config: &Configuration{ + Servers: []string{testServer8.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + Version: 9, + }, + expectedError: false, + }, + { + name: "success with valid configuration with version 1", + config: &Configuration{ + Servers: []string{testServer1.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + { + name: "success with valid configuration with version 2", + config: &Configuration{ + Servers: []string{testServer2.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + { + name: "success with valid configuration password from file", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "", + LogLevel: "debug", + Username: "user", + PasswordFilePath: pwdFile, + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + { + name: "fali with configuration password and password from file are set", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: pwdFile, + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: true, + }, + { + name: "fail with missing server", + config: &Configuration{ + Servers: []string{}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "debug", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: true, + }, + { + name: "fail with invalid configuration invalid loglevel", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "invalid", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: true, + }, + { + name: "fail with invalid configuration invalid bulkworkers number", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "invalid", + Username: "user", + PasswordFilePath: "", + BulkWorkers: 0, + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: true, + }, + { + name: "success with valid configuration and info log level", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "info", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + { + name: "success with valid configuration and error log level", + config: &Configuration{ + Servers: []string{testServer.URL}, + AllowTokenFromContext: true, + Password: "secret", + LogLevel: "error", + Username: "user", + PasswordFilePath: "", + BulkSize: -1, // disable bulk; we want immediate flush + }, + expectedError: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + logger := zap.NewNop() + metricsFactory := metrics.NullFactory + config := test.config + client, err := NewClient(config, logger, metricsFactory) + if test.expectedError { + require.Error(t, err) + require.Nil(t, client) + } else { + require.NoError(t, err) + require.NotNil(t, client) + err = client.Close() + require.NoError(t, err) + } + err = config.TLS.Close() + require.NoError(t, err) + }) + } +} + +func TestApplyDefaults(t *testing.T) { + source := &Configuration{ + RemoteReadClusters: []string{"cluster1", "cluster2"}, + Username: "sourceUser", + Password: "sourcePass", + Sniffer: true, + MaxSpanAge: 100, + AdaptiveSamplingLookback: 50, + NumShards: 5, + NumReplicas: 1, + PrioritySpanTemplate: 10, + PriorityServiceTemplate: 20, + PriorityDependenciesTemplate: 30, + BulkSize: 1000, + BulkWorkers: 10, + BulkActions: 100, + BulkFlushInterval: 30, + SnifferTLSEnabled: true, + Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, + MaxDocCount: 10000, + LogLevel: "info", + SendGetBodyAs: "json", + } + + tests := []struct { + name string + target *Configuration + expected *Configuration + }{ + { + name: "All Defaults Applied except PriorityDependenciesTemplate", + target: &Configuration{ + PriorityDependenciesTemplate: 30, + }, // All fields are empty + expected: source, + }, + { + name: "Some Defaults Applied", + target: &Configuration{ + RemoteReadClusters: []string{"customCluster"}, + Username: "customUser", + PrioritySpanTemplate: 10, + PriorityServiceTemplate: 20, + PriorityDependenciesTemplate: 30, + // Other fields left default + }, + expected: &Configuration{ + RemoteReadClusters: []string{"customCluster"}, + Username: "customUser", + Password: "sourcePass", + Sniffer: true, + SnifferTLSEnabled: true, + MaxSpanAge: 100, + AdaptiveSamplingLookback: 50, + NumShards: 5, + NumReplicas: 1, + PrioritySpanTemplate: 10, + PriorityServiceTemplate: 20, + PriorityDependenciesTemplate: 30, + BulkSize: 1000, + BulkWorkers: 10, + BulkActions: 100, + BulkFlushInterval: 30, + Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, + MaxDocCount: 10000, + LogLevel: "info", + SendGetBodyAs: "json", + }, + }, + { + name: "No Defaults Applied", + target: &Configuration{ + RemoteReadClusters: []string{"cluster1", "cluster2"}, + Username: "sourceUser", + Password: "sourcePass", + Sniffer: true, + MaxSpanAge: 100, + AdaptiveSamplingLookback: 50, + NumShards: 5, + NumReplicas: 1, + PrioritySpanTemplate: 10, + PriorityServiceTemplate: 20, + PriorityDependenciesTemplate: 30, + BulkSize: 1000, + BulkWorkers: 10, + BulkActions: 100, + BulkFlushInterval: 30, + SnifferTLSEnabled: true, + Tags: TagsAsFields{AllAsFields: true, DotReplacement: "dot", Include: "include", File: "file"}, + MaxDocCount: 10000, + LogLevel: "info", + SendGetBodyAs: "json", + }, + expected: source, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + test.target.ApplyDefaults(source) + require.Equal(t, test.expected, test.target) + }) + } +} + +func TestTagKeysAsFields(t *testing.T) { + const ( + pwd1 = "tag1\ntag2" + ) + pwdFile := filepath.Join(t.TempDir(), "pwd") + require.NoError(t, os.WriteFile(pwdFile, []byte(pwd1), 0o600)) + + tests := []struct { + name string + config *Configuration + expectedTags []string + expectError bool + }{ + { + name: "File with tags", + config: &Configuration{ + Tags: TagsAsFields{ + File: pwdFile, + Include: "", + }, + }, + expectedTags: []string{"tag1", "tag2"}, + expectError: false, + }, + { + name: "include with tags", + config: &Configuration{ + Tags: TagsAsFields{ + File: "", + Include: "cmdtag1,cmdtag2", + }, + }, + expectedTags: []string{"cmdtag1", "cmdtag2"}, + expectError: false, + }, + { + name: "File and include with tags", + config: &Configuration{ + Tags: TagsAsFields{ + File: pwdFile, + Include: "cmdtag1,cmdtag2", + }, + }, + expectedTags: []string{"tag1", "tag2", "cmdtag1", "cmdtag2"}, + expectError: false, + }, + { + name: "File read error", + config: &Configuration{ + Tags: TagsAsFields{ + File: "/invalid/path/to/file.txt", + Include: "", + }, + }, + expectedTags: nil, + expectError: true, + }, + { + name: "Empty file and params", + config: &Configuration{ + Tags: TagsAsFields{ + File: "", + Include: "", + }, + }, + expectedTags: nil, + expectError: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + tags, err := test.config.TagKeysAsFields() + + if test.expectError { + require.Error(t, err) + require.Nil(t, tags) + } else { + require.NoError(t, err) + require.ElementsMatch(t, test.expectedTags, tags) + } + }) + } +} + +func TestGetIndexRolloverFrequencySpansDuration(t *testing.T) { + tests := []struct { + name string + indexFrequency string + expected time.Duration + }{ + { + name: "hourly jaeger-span", + indexFrequency: "hour", + expected: -1 * time.Hour, + }, + { + name: "daily jaeger-span", + indexFrequency: "daily", + expected: -24 * time.Hour, + }, + { + name: "empty jaeger-span", + indexFrequency: "", + expected: -24 * time.Hour, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + c := &Configuration{IndexRolloverFrequencySpans: test.indexFrequency} + got := c.GetIndexRolloverFrequencySpansDuration() + require.Equal(t, test.expected, got) + }) + } +} + +func TestGetIndexRolloverFrequencyServicesDuration(t *testing.T) { + tests := []struct { + name string + indexFrequency string + expected time.Duration + }{ + { + name: "hourly jaeger-service", + indexFrequency: "hour", + expected: -1 * time.Hour, + }, + { + name: "daily jaeger-service", + indexFrequency: "daily", + expected: -24 * time.Hour, + }, + { + name: "empty jaeger-service", + indexFrequency: "", + expected: -24 * time.Hour, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + c := &Configuration{IndexRolloverFrequencyServices: test.indexFrequency} + got := c.GetIndexRolloverFrequencyServicesDuration() + require.Equal(t, test.expected, got) + }) + } +} + +func TestGetIndexRolloverFrequencySamplingDuration(t *testing.T) { + tests := []struct { + name string + indexFrequency string + expected time.Duration + }{ + { + name: "hourly jaeger-sampling", + indexFrequency: "hour", + expected: -1 * time.Hour, + }, + { + name: "daily jaeger-sampling", + indexFrequency: "daily", + expected: -24 * time.Hour, + }, + { + name: "empty jaeger-sampling", + indexFrequency: "", + expected: -24 * time.Hour, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + c := &Configuration{IndexRolloverFrequencySampling: test.indexFrequency} + got := c.GetIndexRolloverFrequencySamplingDuration() + require.Equal(t, test.expected, got) + }) + } +} + +func TestValidate(t *testing.T) { + tests := []struct { + name string + config *Configuration + expectedError bool + }{ + { + name: "All valid input are set", + config: &Configuration{ + Servers: []string{"localhost:8000/dummyserver"}, + }, + expectedError: false, + }, + { + name: "no valid input are set", + config: &Configuration{}, + expectedError: true, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.config.Validate() + if test.expectedError { + require.Error(t, got) + } else { + require.NoError(t, got) + } + }) + } +} + +func TestMain(m *testing.M) { + testutils.VerifyGoLeaks(m) +} From a6ccf56ca0b67d1088b7dad3c58e9212c8c66e58 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Fri, 9 Aug 2024 01:05:43 -0300 Subject: [PATCH 6/8] Clearer output from lint scripts (#5820) --- scripts/check-goleak-files.sh | 11 +++++++---- scripts/check-test-files.sh | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/check-goleak-files.sh b/scripts/check-goleak-files.sh index 47d61295a01..e15fc790e57 100755 --- a/scripts/check-goleak-files.sh +++ b/scripts/check-goleak-files.sh @@ -3,10 +3,12 @@ set -euo pipefail bad_pkgs=0 +total_pkgs=0 failed_pkgs=0 # shellcheck disable=SC2048 for dir in $*; do + ((total_pkgs+=1)) if [[ -f "${dir}/.nocover" ]]; then continue fi @@ -22,10 +24,10 @@ for dir in $*; do fi done if ((good == 0)); then - echo "🔴 Error(check-goleak): no goleak check in package ${dir}" + echo "Error(check-goleak): no goleak check in package ${dir}" ((bad_pkgs+=1)) if [[ "${dir}" == "./cmd/jaeger/internal/integration/" || "${dir}" == "./plugin/storage/integration/" ]]; then - echo " this package is temporarily allowed and will not cause linter failure" + echo " ... this package is temporarily allowed and will not cause linter failure" else ((failed_pkgs+=1)) fi @@ -33,8 +35,7 @@ for dir in $*; do done function help() { - echo " See https://github.com/jaegertracing/jaeger/pull/5010/files" - echo " for examples of adding the checks." + echo " See pkg/version/package_test.go as example of adding the checks." } if ((failed_pkgs > 0)); then @@ -44,4 +45,6 @@ if ((failed_pkgs > 0)); then elif ((bad_pkgs > 0)); then echo "🐞 Warning(check-goleak): no goleak check in ${bad_pkgs} package(s)." help +else + echo "✅ Info(check-goleak): no issues after scanning ${total_pkgs} package(s)." fi diff --git a/scripts/check-test-files.sh b/scripts/check-test-files.sh index 7ffc896688c..8e7386501e7 100755 --- a/scripts/check-test-files.sh +++ b/scripts/check-test-files.sh @@ -9,9 +9,11 @@ set -euo pipefail NO_TEST_FILE_DIRS="" +total_pkgs=0 # shellcheck disable=SC2048 for dir in $*; do + ((total_pkgs+=1)) mainFile=$(find "${dir}" -maxdepth 1 -name 'main.go') testFiles=$(find "${dir}" -maxdepth 1 -name '*_test.go') if [ -z "${testFiles}" ]; then @@ -42,4 +44,6 @@ if [ -n "${NO_TEST_FILE_DIRS}" ]; then echo "error: at least one *_test.go file must be in all directories with go files so that they are counted for code coverage" >&2 echo " if no tests are possible for a package (e.g. it only defines types), create empty_test.go" >&2 exit 1 +else + echo "✅ Info(check-test-files): no issues after scanning ${total_pkgs} package(s)." fi From 666c2084d5878acce199ce5c51b772cfbce1e703 Mon Sep 17 00:00:00 2001 From: Viral Verma <102751195+vvs-personalstash@users.noreply.github.com> Date: Mon, 12 Aug 2024 03:26:44 +0530 Subject: [PATCH 7/8] Clean up obselete 'version' tag from docker-compose files (#5826) ## Description of the changes - As the latest updates in docker compose has deprecated the 'version' tag.This Pr aims to cleanup the version tags in the various docker-compose files so as to cleanup the log currently displaying ```'version' is obselete ``` when we run a docker-compose file. ## Checklist - [ :white_check_mark: ] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [ :white_check_mark: ] I have signed all commits - [ :x:] I have added unit tests for the new functionality - [ :white_check_mark: ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` Signed-off-by: vvs-personalstash --- cmd/tracegen/docker-compose.yml | 2 -- crossdock/docker-compose.yml | 2 -- crossdock/jaeger-docker-compose.yml | 2 -- docker-compose/cassandra/v3/docker-compose.yaml | 2 -- docker-compose/cassandra/v4/docker-compose.yaml | 2 -- docker-compose/elasticsearch/v6/docker-compose.yml | 2 -- docker-compose/elasticsearch/v7/docker-compose.yml | 2 -- docker-compose/elasticsearch/v8/docker-compose.yml | 2 -- docker-compose/jaeger-docker-compose.yml | 2 -- docker-compose/kafka-integration-test/docker-compose.yml | 2 -- docker-compose/kafka/docker-compose.yml | 2 -- docker-compose/monitor/docker-compose-v2.yml | 1 - docker-compose/monitor/docker-compose.yml | 1 - docker-compose/opensearch/v1/docker-compose.yml | 2 -- docker-compose/opensearch/v2/docker-compose.yml | 2 -- examples/grafana-integration/docker-compose.yaml | 2 -- examples/hotrod/docker-compose-v2.yml | 1 - examples/hotrod/docker-compose.yml | 1 - examples/reverse-proxy/docker-compose.yml | 2 -- 19 files changed, 34 deletions(-) diff --git a/cmd/tracegen/docker-compose.yml b/cmd/tracegen/docker-compose.yml index e4105261726..a6f07516c43 100644 --- a/cmd/tracegen/docker-compose.yml +++ b/cmd/tracegen/docker-compose.yml @@ -1,5 +1,3 @@ -version: '2' - services: jaeger: image: jaegertracing/all-in-one:latest diff --git a/crossdock/docker-compose.yml b/crossdock/docker-compose.yml index 4bcfd782ef6..fe88cd2e631 100644 --- a/crossdock/docker-compose.yml +++ b/crossdock/docker-compose.yml @@ -1,5 +1,3 @@ -version: '2' - services: crossdock: image: crossdock/crossdock diff --git a/crossdock/jaeger-docker-compose.yml b/crossdock/jaeger-docker-compose.yml index 877b752e355..ef90fea73a4 100644 --- a/crossdock/jaeger-docker-compose.yml +++ b/crossdock/jaeger-docker-compose.yml @@ -1,5 +1,3 @@ -version: '2' - services: jaeger-remote-storage: image: jaegertracing/jaeger-remote-storage diff --git a/docker-compose/cassandra/v3/docker-compose.yaml b/docker-compose/cassandra/v3/docker-compose.yaml index fefe7cc53fa..fdca44acfe7 100644 --- a/docker-compose/cassandra/v3/docker-compose.yaml +++ b/docker-compose/cassandra/v3/docker-compose.yaml @@ -1,5 +1,3 @@ -version: '3.8' - services: cassandra: image: cassandra:3.11 diff --git a/docker-compose/cassandra/v4/docker-compose.yaml b/docker-compose/cassandra/v4/docker-compose.yaml index c54e71b1bb3..2b8ef6d38f6 100644 --- a/docker-compose/cassandra/v4/docker-compose.yaml +++ b/docker-compose/cassandra/v4/docker-compose.yaml @@ -1,5 +1,3 @@ -version: '3.8' - services: cassandra: image: cassandra:4.1 diff --git a/docker-compose/elasticsearch/v6/docker-compose.yml b/docker-compose/elasticsearch/v6/docker-compose.yml index fdce40870e9..7fcc6b81671 100644 --- a/docker-compose/elasticsearch/v6/docker-compose.yml +++ b/docker-compose/elasticsearch/v6/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.23 diff --git a/docker-compose/elasticsearch/v7/docker-compose.yml b/docker-compose/elasticsearch/v7/docker-compose.yml index a608b214eef..14ef1e7f138 100644 --- a/docker-compose/elasticsearch/v7/docker-compose.yml +++ b/docker-compose/elasticsearch/v7/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:7.17.22 diff --git a/docker-compose/elasticsearch/v8/docker-compose.yml b/docker-compose/elasticsearch/v8/docker-compose.yml index 02b2b1e413e..5de4f2c35bd 100644 --- a/docker-compose/elasticsearch/v8/docker-compose.yml +++ b/docker-compose/elasticsearch/v8/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:8.14.1 diff --git a/docker-compose/jaeger-docker-compose.yml b/docker-compose/jaeger-docker-compose.yml index c478beb0e28..1d024e1521c 100644 --- a/docker-compose/jaeger-docker-compose.yml +++ b/docker-compose/jaeger-docker-compose.yml @@ -1,5 +1,3 @@ -version: '2' - services: hotrod: image: jaegertracing/example-hotrod:latest diff --git a/docker-compose/kafka-integration-test/docker-compose.yml b/docker-compose/kafka-integration-test/docker-compose.yml index f4597201db4..73859560643 100644 --- a/docker-compose/kafka-integration-test/docker-compose.yml +++ b/docker-compose/kafka-integration-test/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: kafka: image: bitnami/kafka:3.7.0 diff --git a/docker-compose/kafka/docker-compose.yml b/docker-compose/kafka/docker-compose.yml index 243ff1d3ed3..9eb2130559c 100644 --- a/docker-compose/kafka/docker-compose.yml +++ b/docker-compose/kafka/docker-compose.yml @@ -1,5 +1,3 @@ -version: "2.1" - services: zookeeper: image: bitnami/zookeeper diff --git a/docker-compose/monitor/docker-compose-v2.yml b/docker-compose/monitor/docker-compose-v2.yml index 5bddd2cc658..890ab856849 100644 --- a/docker-compose/monitor/docker-compose-v2.yml +++ b/docker-compose/monitor/docker-compose-v2.yml @@ -1,4 +1,3 @@ -version: "3.5" services: jaeger: networks: diff --git a/docker-compose/monitor/docker-compose.yml b/docker-compose/monitor/docker-compose.yml index 3f288201eb9..ac6b03b620b 100644 --- a/docker-compose/monitor/docker-compose.yml +++ b/docker-compose/monitor/docker-compose.yml @@ -1,4 +1,3 @@ -version: "3.5" services: jaeger: networks: diff --git a/docker-compose/opensearch/v1/docker-compose.yml b/docker-compose/opensearch/v1/docker-compose.yml index 09a1cdc4715..8a95bb702f3 100644 --- a/docker-compose/opensearch/v1/docker-compose.yml +++ b/docker-compose/opensearch/v1/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: opensearch: image: opensearchproject/opensearch:1.3.17 diff --git a/docker-compose/opensearch/v2/docker-compose.yml b/docker-compose/opensearch/v2/docker-compose.yml index 4c0c6ddfc0d..6738f208271 100644 --- a/docker-compose/opensearch/v2/docker-compose.yml +++ b/docker-compose/opensearch/v2/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: opensearch: image: opensearchproject/opensearch:2.15.0 diff --git a/examples/grafana-integration/docker-compose.yaml b/examples/grafana-integration/docker-compose.yaml index 8751a58f47e..e5031b4ac35 100644 --- a/examples/grafana-integration/docker-compose.yaml +++ b/examples/grafana-integration/docker-compose.yaml @@ -1,5 +1,3 @@ -version: '2' - services: grafana: image: grafana/grafana:10.2.2 diff --git a/examples/hotrod/docker-compose-v2.yml b/examples/hotrod/docker-compose-v2.yml index 062cfe7703e..29b0491a030 100644 --- a/examples/hotrod/docker-compose-v2.yml +++ b/examples/hotrod/docker-compose-v2.yml @@ -1,4 +1,3 @@ -version: '3.7' # To run a specific version of Jaeger, use environment variable, e.g.: # JAEGER_VERSION=1.52 docker compose up diff --git a/examples/hotrod/docker-compose.yml b/examples/hotrod/docker-compose.yml index 048de7de59e..4566e2863da 100644 --- a/examples/hotrod/docker-compose.yml +++ b/examples/hotrod/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.7' # To run a specific version of Jaeger, use environment variable, e.g.: # JAEGER_VERSION=1.52 docker compose up diff --git a/examples/reverse-proxy/docker-compose.yml b/examples/reverse-proxy/docker-compose.yml index 0e368ffbd4f..9521e9e511f 100644 --- a/examples/reverse-proxy/docker-compose.yml +++ b/examples/reverse-proxy/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.7' - services: jaeger: image: jaegertracing/all-in-one:latest From f1db79c7930f1711e000e736781bdc42cb3f3b41 Mon Sep 17 00:00:00 2001 From: Kaung Zin Hein <83657429+Zen-cronic@users.noreply.github.com> Date: Sun, 11 Aug 2024 18:00:30 -0400 Subject: [PATCH 8/8] Regenerate mocks (#5821) ## Which problem is this PR solving? - Resolves #5818 ## Description of the changes - Generate mocked interfaces in `plugin/storage/grpc/shared/mocks` instead of `plugin/storage/grpc/mocks` ## How was this change tested? - `make test` ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Kaung Zin Hein Co-authored-by: Yuri Shkuro --- .mockery.yaml | 2 +- plugin/storage/grpc/factory_test.go | 2 +- .../storage/grpc/mocks/PluginCapabilities.go | 51 --------------- .../grpc/shared/mocks/PluginCapabilities.go | 62 +++++++++++++++++++ 4 files changed, 64 insertions(+), 53 deletions(-) delete mode 100644 plugin/storage/grpc/mocks/PluginCapabilities.go create mode 100644 plugin/storage/grpc/shared/mocks/PluginCapabilities.go diff --git a/.mockery.yaml b/.mockery.yaml index 9f46e45ae22..48f9c27d4b9 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -42,7 +42,7 @@ packages: github.com/jaegertracing/jaeger/plugin/sampling/leaderelection: config: all: true - github.com/jaegertracing/jaeger/plugin/storage/grpc: + github.com/jaegertracing/jaeger/plugin/storage/grpc/shared: interfaces: PluginCapabilities: github.com/jaegertracing/jaeger/plugin/storage/kafka: diff --git a/plugin/storage/grpc/factory_test.go b/plugin/storage/grpc/factory_test.go index 94e1b0c4ddc..36dcf885dd7 100644 --- a/plugin/storage/grpc/factory_test.go +++ b/plugin/storage/grpc/factory_test.go @@ -34,8 +34,8 @@ import ( "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/metrics" - "github.com/jaegertracing/jaeger/plugin/storage/grpc/mocks" "github.com/jaegertracing/jaeger/plugin/storage/grpc/shared" + "github.com/jaegertracing/jaeger/plugin/storage/grpc/shared/mocks" "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/dependencystore" dependencyStoreMocks "github.com/jaegertracing/jaeger/storage/dependencystore/mocks" diff --git a/plugin/storage/grpc/mocks/PluginCapabilities.go b/plugin/storage/grpc/mocks/PluginCapabilities.go deleted file mode 100644 index 7d72d623594..00000000000 --- a/plugin/storage/grpc/mocks/PluginCapabilities.go +++ /dev/null @@ -1,51 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -// Copyright (c) 2020 The Jaeger Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mocks - -import ( - mock "github.com/stretchr/testify/mock" - - "github.com/jaegertracing/jaeger/plugin/storage/grpc/shared" -) - -// PluginCapabilities is an autogenerated mock type for the PluginCapabilities type -type PluginCapabilities struct { - mock.Mock -} - -// Capabilities provides a mock function with given fields: -func (_m *PluginCapabilities) Capabilities() (*shared.Capabilities, error) { - ret := _m.Called() - - var r0 *shared.Capabilities - if rf, ok := ret.Get(0).(func() *shared.Capabilities); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*shared.Capabilities) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} diff --git a/plugin/storage/grpc/shared/mocks/PluginCapabilities.go b/plugin/storage/grpc/shared/mocks/PluginCapabilities.go new file mode 100644 index 00000000000..abe2c24a982 --- /dev/null +++ b/plugin/storage/grpc/shared/mocks/PluginCapabilities.go @@ -0,0 +1,62 @@ +// Copyright (c) The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 +// +// Run 'make generate-mocks' to regenerate. + +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + shared "github.com/jaegertracing/jaeger/plugin/storage/grpc/shared" + mock "github.com/stretchr/testify/mock" +) + +// PluginCapabilities is an autogenerated mock type for the PluginCapabilities type +type PluginCapabilities struct { + mock.Mock +} + +// Capabilities provides a mock function with given fields: +func (_m *PluginCapabilities) Capabilities() (*shared.Capabilities, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Capabilities") + } + + var r0 *shared.Capabilities + var r1 error + if rf, ok := ret.Get(0).(func() (*shared.Capabilities, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *shared.Capabilities); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*shared.Capabilities) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewPluginCapabilities creates a new instance of PluginCapabilities. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewPluginCapabilities(t interface { + mock.TestingT + Cleanup(func()) +}) *PluginCapabilities { + mock := &PluginCapabilities{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}