Skip to content

Commit

Permalink
[jaeger-v2] add elasticsearch & opensearch e2e integration test (jaeg…
Browse files Browse the repository at this point in the history
…ertracing#5345)

## Which problem is this PR solving?
- part of jaegertracing#5254 

## Description of the changes
- Utilizing existing `StorageIntegration` to test the jaeger-v2 OTel
Collector and gRPC storage backend with the provided config file at
`cmd/jaeger/config-elasticsearch.yaml`.

## How was this change tested?
- Start a elasticsearch or opensearch docker instance.
- Run `STORAGE=elasticsearch SPAN_STORAGE_TYPE=elasticsearch make
jaeger-v2-storage-integration-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: Pushkar Mishra <[email protected]>
  • Loading branch information
Pushkarm029 committed May 4, 2024
1 parent a15962b commit fab02d8
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 75 deletions.
7 changes: 5 additions & 2 deletions cmd/jaeger/config-elasticsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ extensions:
server_urls: http://localhost:9200
log_level: "error"
index_prefix: "jaeger-main"
use_aliases: true
use_aliases: false
create_mappings: true
es_archive:
server_urls: http://localhost:9200
log_level: "error"
index_prefix: "jaeger-archive"
use_aliases: true
use_aliases: false
create_mappings: true

receivers:
otlp:
protocols:
Expand Down
26 changes: 7 additions & 19 deletions cmd/jaeger/config-opensearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,18 @@ extensions:
jaeger_storage:
opensearch:
os_main:
server_urls: https://localhost:9200
server_urls: http://localhost:9200
log_level: "error"
index_prefix: "jaeger-main"
use_aliases: true
username: "admin"
password: "admin"
tls:
enabled: true
skip_host_verify: true
tags_as_fields:
all: true
use_aliases: false
create_mappings: true

os_archive:
server_urls: https://localhost:9200
server_urls: http://localhost:9200
log_level: "error"
index_prefix: "jaeger-archive"
use_aliases: true
username: "admin"
password: "admin"
tls:
enabled: true
skip_host_verify: true
tags_as_fields:
all: true
index_prefix: "jaeger-main"
use_aliases: false
create_mappings: true

receivers:
otlp:
Expand Down
23 changes: 2 additions & 21 deletions cmd/jaeger/internal/integration/badger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,11 @@
package integration

import (
"fmt"
"net/http"
"testing"

"github.com/stretchr/testify/require"

"github.com/jaegertracing/jaeger/cmd/jaeger/internal/integration/storagecleaner"
"github.com/jaegertracing/jaeger/plugin/storage/integration"
)

func cleanUp(t *testing.T) {
Addr := fmt.Sprintf("http://0.0.0.0:%s%s", storagecleaner.Port, storagecleaner.URL)
r, err := http.NewRequest(http.MethodPost, Addr, nil)
require.NoError(t, err)

client := &http.Client{}

resp, err := client.Do(r)
require.NoError(t, err)
defer resp.Body.Close()

require.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestBadgerStorage(t *testing.T) {
integration.SkipUnlessEnv(t, "badger")

Expand All @@ -36,14 +17,14 @@ func TestBadgerStorage(t *testing.T) {
StorageIntegration: integration.StorageIntegration{
SkipBinaryAttrs: true,
SkipArchiveTest: true,
CleanUp: cleanUp,
CleanUp: purge,

// TODO: remove this once badger supports returning spanKind from GetOperations
// Cf https://github.com/jaegertracing/jaeger/issues/1922
GetOperationsMissingSpanKind: true,
},
}
s.e2eInitialize(t)
s.e2eInitialize(t, "badger")
t.Cleanup(func() {
s.e2eCleanUp(t)
})
Expand Down
43 changes: 40 additions & 3 deletions cmd/jaeger/internal/integration/e2e_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"

"github.com/jaegertracing/jaeger/cmd/jaeger/internal/integration/storagecleaner"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/integration"
"github.com/jaegertracing/jaeger/ports"
Expand All @@ -42,9 +43,9 @@ type E2EStorageIntegration struct {
// e2eInitialize starts the Jaeger-v2 collector with the provided config file,
// it also initialize the SpanWriter and SpanReader below.
// This function should be called before any of the tests start.
func (s *E2EStorageIntegration) e2eInitialize(t *testing.T) {
func (s *E2EStorageIntegration) e2eInitialize(t *testing.T, storage string) {
logger, _ := testutils.NewLogger()
configFile := createStorageCleanerConfig(t, s.ConfigFile)
configFile := createStorageCleanerConfig(t, s.ConfigFile, storage)
t.Logf("Starting Jaeger-v2 in the background with config file %s", configFile)
cmd := exec.Cmd{
Path: "./cmd/jaeger/jaeger",
Expand Down Expand Up @@ -91,7 +92,7 @@ func (s *E2EStorageIntegration) e2eCleanUp(t *testing.T) {
require.NoError(t, s.SpanWriter.(io.Closer).Close())
}

func createStorageCleanerConfig(t *testing.T, configFile string) string {
func createStorageCleanerConfig(t *testing.T, configFile string, storage string) string {
data, err := os.ReadFile(configFile)
require.NoError(t, err)
var config map[string]interface{}
Expand All @@ -109,6 +110,28 @@ func createStorageCleanerConfig(t *testing.T, configFile string) string {
trace_storage := query["trace_storage"].(string)
extensions["storage_cleaner"] = map[string]string{"trace_storage": trace_storage}

jaegerStorage, ok := extensions["jaeger_storage"].(map[string]interface{})
require.True(t, ok)

switch storage {
case "elasticsearch":
elasticsearch, ok := jaegerStorage["elasticsearch"].(map[string]interface{})
require.True(t, ok)
esMain, ok := elasticsearch["es_main"].(map[string]interface{})
require.True(t, ok)
esMain["service_cache_ttl"] = "1ms"

case "opensearch":
opensearch, ok := jaegerStorage["opensearch"].(map[string]interface{})
require.True(t, ok)
osMain, ok := opensearch["os_main"].(map[string]interface{})
require.True(t, ok)
osMain["service_cache_ttl"] = "1ms"

default:
// Do Nothing
}

newData, err := yaml.Marshal(config)
require.NoError(t, err)
tempFile := filepath.Join(t.TempDir(), "storageCleaner_config.yaml")
Expand All @@ -117,3 +140,17 @@ func createStorageCleanerConfig(t *testing.T, configFile string) string {

return tempFile
}

func purge(t *testing.T) {
Addr := fmt.Sprintf("http://0.0.0.0:%s%s", storagecleaner.Port, storagecleaner.URL)
r, err := http.NewRequestWithContext(context.Background(), http.MethodPost, Addr, nil)
require.NoError(t, err)

client := &http.Client{}

resp, err := client.Do(r)
require.NoError(t, err)
defer resp.Body.Close()

require.Equal(t, http.StatusOK, resp.StatusCode)
}
29 changes: 29 additions & 0 deletions cmd/jaeger/internal/integration/es_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package integration

import (
"testing"

"github.com/jaegertracing/jaeger/plugin/storage/integration"
)

func TestESStorage(t *testing.T) {
integration.SkipUnlessEnv(t, "elasticsearch")

s := &E2EStorageIntegration{
ConfigFile: "../../config-elasticsearch.yaml",
StorageIntegration: integration.StorageIntegration{
CleanUp: purge,
Fixtures: integration.LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
SkipBinaryAttrs: true,
GetOperationsMissingSpanKind: true,
},
}
s.e2eInitialize(t, "elasticsearch")
t.Cleanup(func() {
s.e2eCleanUp(t)
})
s.RunSpanStoreTests(t)
}
2 changes: 1 addition & 1 deletion cmd/jaeger/internal/integration/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGRPCStorage(t *testing.T) {
}
s.CleanUp = s.cleanUp
s.initialize(t)
s.e2eInitialize(t)
s.e2eInitialize(t, "grpc")
t.Cleanup(func() {
s.e2eCleanUp(t)
s.remoteStorage.Close(t)
Expand Down
28 changes: 28 additions & 0 deletions cmd/jaeger/internal/integration/os_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package integration

import (
"testing"

"github.com/jaegertracing/jaeger/plugin/storage/integration"
)

func TestOSStorage(t *testing.T) {
integration.SkipUnlessEnv(t, "opensearch")
s := &E2EStorageIntegration{
ConfigFile: "../../config-opensearch.yaml",
StorageIntegration: integration.StorageIntegration{
CleanUp: purge,
Fixtures: integration.LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
SkipBinaryAttrs: true,
GetOperationsMissingSpanKind: true,
},
}
s.e2eInitialize(t, "opensearch")
t.Cleanup(func() {
s.e2eCleanUp(t)
})
s.RunSpanStoreTests(t)
}
4 changes: 2 additions & 2 deletions plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func NewFactoryWithConfig(
return nil, err
}

cfg.MaxDocCount = defaultMaxDocCount
cfg.Enabled = true
defaultConfig := getDefaultConfig()
cfg.ApplyDefaults(&defaultConfig)

archive := make(map[string]*namespaceConfig)
archive[archiveNamespace] = &namespaceConfig{
Expand Down
60 changes: 33 additions & 27 deletions plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,7 @@ type namespaceConfig struct {
// NewOptions creates a new Options struct.
func NewOptions(primaryNamespace string, otherNamespaces ...string) *Options {
// TODO all default values should be defined via cobra flags
defaultConfig := config.Configuration{
Username: "",
Password: "",
Sniffer: false,
MaxSpanAge: 72 * time.Hour,
AdaptiveSamplingLookback: 72 * time.Hour,
NumShards: 5,
NumReplicas: 1,
PrioritySpanTemplate: 0,
PriorityServiceTemplate: 0,
PriorityDependenciesTemplate: 0,
BulkSize: 5 * 1000 * 1000,
BulkWorkers: 1,
BulkActions: 1000,
BulkFlushInterval: time.Millisecond * 200,
Tags: config.TagsAsFields{
DotReplacement: "@",
},
Enabled: true,
CreateIndexTemplates: true,
Version: 0,
Servers: []string{defaultServerURL},
RemoteReadClusters: []string{},
MaxDocCount: defaultMaxDocCount,
LogLevel: "error",
SendGetBodyAs: defaultSendGetBodyAs,
}
defaultConfig := getDefaultConfig()
options := &Options{
Primary: namespaceConfig{
Configuration: defaultConfig,
Expand Down Expand Up @@ -433,3 +407,35 @@ func initDateLayout(rolloverFreq, sep string) string {
}
return indexLayout
}

func getDefaultConfig() config.Configuration {
return config.Configuration{
Username: "",
Password: "",
Sniffer: false,
MaxSpanAge: 72 * time.Hour,
AdaptiveSamplingLookback: 72 * time.Hour,
NumShards: 5,
NumReplicas: 1,
PrioritySpanTemplate: 0,
PriorityServiceTemplate: 0,
PriorityDependenciesTemplate: 0,
BulkSize: 5 * 1000 * 1000,
BulkWorkers: 1,
BulkActions: 1000,
BulkFlushInterval: time.Millisecond * 200,
Tags: config.TagsAsFields{
DotReplacement: "@",
},
Enabled: true,
CreateIndexTemplates: true,
Version: 0,
UseReadWriteAliases: false,
UseILM: false,
Servers: []string{defaultServerURL},
RemoteReadClusters: []string{},
MaxDocCount: defaultMaxDocCount,
LogLevel: "error",
SendGetBodyAs: defaultSendGetBodyAs,
}
}
1 change: 1 addition & 0 deletions scripts/es-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ main() {

bring_up_storage "${distro}" "${version}"
STORAGE=${distro} make storage-integration-test
STORAGE=${distro} SPAN_STORAGE_TYPE=${distro} make jaeger-v2-storage-integration-test
make index-cleaner-integration-test
make index-rollover-integration-test
}
Expand Down

0 comments on commit fab02d8

Please sign in to comment.