Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[jaeger-v2] add badger e2e integration test #5355

Merged
merged 76 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
f067287
add badger integration test
akagami-harsh Apr 12, 2024
d64d43d
fix lint
akagami-harsh Apr 12, 2024
aaa202e
Merge branch 'main' into badger-integration
akagami-harsh Apr 13, 2024
9f42757
use SpanWriter and SpanReader from e2eInitialize() functionf
akagami-harsh Apr 14, 2024
ac8dfad
Update cmd/jaeger/internal/integration/badger_test.go
akagami-harsh Apr 14, 2024
8555ebd
Update cmd/jaeger/internal/integration/badger_test.go
akagami-harsh Apr 14, 2024
c6f841e
fix
akagami-harsh Apr 14, 2024
b4bd719
use badger ephemeral
akagami-harsh Apr 14, 2024
0a771df
fix
akagami-harsh Apr 14, 2024
04d6b55
fix lint
akagami-harsh Apr 14, 2024
343a648
assigned static vars when creating struct
akagami-harsh Apr 14, 2024
3795f70
fix
akagami-harsh Apr 14, 2024
40519c3
Merge branch 'main' into badger-integration
akagami-harsh Apr 14, 2024
968f010
rm refresh
akagami-harsh Apr 14, 2024
7783932
Merge branch 'main' into badger-integration
akagami-harsh Apr 19, 2024
28af7df
use normal badger storage
akagami-harsh Apr 20, 2024
cc48bde
revert some changes
akagami-harsh Apr 20, 2024
a15d977
add badger cleaner extension
akagami-harsh Apr 20, 2024
dc4fefc
use badger cleaner extension in the test
akagami-harsh Apr 20, 2024
72e2787
Merge branch 'main' into badger-integration
akagami-harsh Apr 20, 2024
39b38ae
fix
akagami-harsh Apr 20, 2024
914cddf
fix
akagami-harsh Apr 20, 2024
5a293f2
fix
akagami-harsh Apr 20, 2024
118f998
fix lint
akagami-harsh Apr 20, 2024
b993e31
rm unwanted changes
akagami-harsh Apr 20, 2024
e7373d1
Update cmd/jaeger/internal/integration/badgercleaner/factory.go
akagami-harsh Apr 20, 2024
06ea8aa
increase span store ttl to 30d
akagami-harsh Apr 21, 2024
2acbefa
add check for status code
akagami-harsh Apr 21, 2024
5232516
fix
akagami-harsh Apr 21, 2024
f14fd56
add cleaner port in the config
akagami-harsh Apr 21, 2024
30f43e6
use temp file for the config
akagami-harsh Apr 21, 2024
a03b781
Merge branch 'main' into badger-integration
akagami-harsh Apr 21, 2024
fa83996
refactor the extenstion to make it more generic and address open comm…
akagami-harsh Apr 21, 2024
15ddf59
Update cmd/jaeger/badger_config.yaml
akagami-harsh Apr 22, 2024
ca6b23d
make port and url public consts
akagami-harsh Apr 22, 2024
6d6d870
add factory test
akagami-harsh Apr 22, 2024
031bf15
add goleak check and fix lint
akagami-harsh Apr 22, 2024
a5a4e56
fix
akagami-harsh Apr 22, 2024
ee84793
create storage.Purger interface
akagami-harsh Apr 22, 2024
f35a6a4
rm temp file from t.cleanup and use fmt.Sprintf insted of constants
akagami-harsh Apr 22, 2024
4ef7ad8
Update cmd/jaeger/internal/integration/storagecleaner/extension.go
akagami-harsh Apr 22, 2024
07c642c
Update storage/factory.go
akagami-harsh Apr 22, 2024
b2dd656
Update cmd/jaeger/internal/integration/badger_test.go
akagami-harsh Apr 22, 2024
c0ba470
fix lint
akagami-harsh Apr 22, 2024
794b5b6
Update cmd/jaeger/internal/integration/storagecleaner/README.md
akagami-harsh Apr 23, 2024
0df8a88
Update cmd/jaeger/internal/integration/storagecleaner/README.md
akagami-harsh Apr 23, 2024
667a691
Update cmd/jaeger/internal/integration/storagecleaner/README.md
akagami-harsh Apr 23, 2024
3afb713
Update cmd/jaeger/internal/integration/storagecleaner/README.md
akagami-harsh Apr 23, 2024
87c3f03
enrich config using golang
akagami-harsh Apr 23, 2024
57525ac
fix
akagami-harsh Apr 23, 2024
fcee96a
rm py script
akagami-harsh Apr 23, 2024
df0a423
fix
akagami-harsh Apr 23, 2024
f218e63
fix
akagami-harsh Apr 23, 2024
697346e
fix lint
akagami-harsh Apr 23, 2024
62dbdb0
add config test
akagami-harsh Apr 23, 2024
32c116f
Update cmd/jaeger/internal/integration/integration.go
akagami-harsh Apr 23, 2024
9a008d7
Update cmd/jaeger/internal/integration/integration.go
akagami-harsh Apr 23, 2024
659c9c7
Update cmd/jaeger/internal/integration/integration.go
akagami-harsh Apr 23, 2024
a053b30
fix
akagami-harsh Apr 23, 2024
3783de8
use yaml.v3
akagami-harsh Apr 23, 2024
2c72071
fix
akagami-harsh Apr 23, 2024
9e27a43
Merge branch 'main' into badger-integration
akagami-harsh Apr 23, 2024
2a3750e
add extension.go tests
akagami-harsh Apr 24, 2024
af58359
fix
akagami-harsh Apr 24, 2024
bd3d4d7
run makefmt
akagami-harsh Apr 24, 2024
49406bd
fix lint
akagami-harsh Apr 24, 2024
64ae824
fix open comments
akagami-harsh Apr 24, 2024
5c6935e
fix
akagami-harsh Apr 26, 2024
e517f06
fix lint
akagami-harsh Apr 26, 2024
4906bc0
clean up test
yurishkuro Apr 26, 2024
1db0b33
make fmt
yurishkuro Apr 26, 2024
a55c88b
cleanup
yurishkuro Apr 26, 2024
cc01687
add tests
yurishkuro Apr 26, 2024
d162de6
Merge branch 'main' into badger-integration
yurishkuro Apr 26, 2024
927b250
fix tests
yurishkuro Apr 26, 2024
c2fcfe3
rm funky test
yurishkuro Apr 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/ci-badger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ permissions: # added using https://github.com/step-security/secure-workflows
jobs:
badger:
runs-on: ubuntu-latest
strategy:
matrix:
version: [v1, v2]
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
Expand All @@ -31,7 +34,16 @@ jobs:
go-version: 1.22.x

- name: Run Badger storage integration tests
run: make badger-storage-integration-test
run: |
case ${{ matrix.version }} in
v1)
make badger-storage-integration-test
;;
v2)
STORAGE=badger \
make jaeger-v2-storage-integration-test
;;
esac
- name: Setup CODECOV_TOKEN
uses: ./.github/actions/setup-codecov
Expand Down
2 changes: 2 additions & 0 deletions cmd/jaeger/badger_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ extensions:
ephemeral: false
maintenance_interval: 5
metrics_update_interval: 10
span_store_ttl: 72h
badger_archive:
directory_key: "/tmp/jaeger_archive/"
directory_value: "/tmp/jaeger_archive/"
ephemeral: false
maintenance_interval: 5
metrics_update_interval: 10
span_store_ttl: 720h
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

receivers:
otlp:
Expand Down
2 changes: 2 additions & 0 deletions cmd/jaeger/internal/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/exporters/storageexporter"
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerquery"
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage"
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/integration/storagecleaner"
)

type builders struct {
Expand Down Expand Up @@ -60,6 +61,7 @@ func (b builders) build() (otelcol.Factories, error) {
// add-ons
jaegerquery.NewFactory(),
jaegerstorage.NewFactory(),
storagecleaner.NewFactory(),
// TODO add adaptive sampling
)
if err != nil {
Expand Down
51 changes: 51 additions & 0 deletions cmd/jaeger/internal/integration/badger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

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)
}
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

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

s := &E2EStorageIntegration{
ConfigFile: "../../badger_config.yaml",
StorageIntegration: integration.StorageIntegration{
SkipBinaryAttrs: true,
SkipArchiveTest: true,
CleanUp: cleanUp,

// TODO: remove this once badger supports returning spanKind from GetOperations
// Cf https://github.com/jaegertracing/jaeger/issues/1922
GetOperationsMissingSpanKind: true,
},
}
s.e2eInitialize(t)
t.Cleanup(func() {
s.e2eCleanUp(t)
})
s.RunAll(t)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much simpler! 10x easier to read. Very nice!

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 @@ -33,7 +33,7 @@ func TestGRPCStorage(t *testing.T) {
integration.SkipUnlessEnv(t, "grpc")

s := &GRPCStorageIntegration{}
s.ConfigFile = "cmd/jaeger/grpc_config.yaml"
s.ConfigFile = "../../grpc_config.yaml"
s.SkipBinaryAttrs = true

s.initialize(t)
Expand Down
32 changes: 32 additions & 0 deletions cmd/jaeger/internal/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
package integration

import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"

"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/integration"
Expand Down Expand Up @@ -38,7 +41,9 @@ type E2EStorageIntegration struct {
// This function should be called before any of the tests start.
func (s *E2EStorageIntegration) e2eInitialize(t *testing.T) {
logger, _ := testutils.NewLogger()
s.ConfigFile = createStorageCleanerConfig(t, s.ConfigFile)
akagami-harsh marked this conversation as resolved.
Show resolved Hide resolved

fmt.Println(s.ConfigFile)
akagami-harsh marked this conversation as resolved.
Show resolved Hide resolved
cmd := exec.Cmd{
Path: "./cmd/jaeger/jaeger",
Args: []string{"jaeger", "--config", s.ConfigFile},
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -67,3 +72,30 @@ func (s *E2EStorageIntegration) e2eCleanUp(t *testing.T) {
require.NoError(t, s.SpanReader.(io.Closer).Close())
require.NoError(t, s.SpanWriter.(io.Closer).Close())
}

func createStorageCleanerConfig(t *testing.T, configFile string) string {
data, err := os.ReadFile(configFile)
require.NoError(t, err)
var config map[interface{}]interface{}
err = yaml.Unmarshal(data, &config)
require.NoError(t, err)

service, ok := config["service"].(map[interface{}]interface{})
require.True(t, ok)
service["extensions"] = append(service["extensions"].([]interface{}), "storage_cleaner")

extensions, ok := config["extensions"].(map[interface{}]interface{})
require.True(t, ok)
query, ok := extensions["jaeger_query"].(map[interface{}]interface{})
require.True(t, ok)
trace_storage := query["trace_storage"].(string)
extensions["storage_cleaner"] = map[string]string{"trace_storage": trace_storage}

newData, err := yaml.Marshal(config)
require.NoError(t, err)
tempFile := filepath.Join(t.TempDir(), "storageCleaner_config.yaml")
err = os.WriteFile(tempFile, newData, 0o600)
require.NoError(t, err)

return tempFile
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ jaeger_storage_receiver/defaults:
trace_storage: storage
jaeger_storage_receiver/filled:
trace_storage: storage
pull_interval: 2s
pull_interval: 2s
47 changes: 47 additions & 0 deletions cmd/jaeger/internal/integration/storagecleaner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# storage_cleaner

This module implements an extension that allows purging the backend storage by making an HTTP POST request to it.

The storage_cleaner extension is intended to be used only in tests, providing a way to clear the storage between test runs. Making a POST request to the exposed endpoint will delete all data in storage.


```mermaid
flowchart LR
Receiver --> Processor
Processor --> Exporter
JaegerStorageExension -->|"(1) get storage"| Exporter
Exporter -->|"(2) write trace"| Storage

E2E_test -->|"(1) POST /purge"| HTTP_endpoint
JaegerStorageExension -->|"(2) getStorage()"| HTTP_endpoint
HTTP_endpoint -.->|"(3) storage.(*storage.Purger).Purge()"| Storage

subgraph Jaeger Collector
Receiver
Processor
Exporter

Storage
StorageCleanerExtension
HTTP_endpoint
subgraph JaegerStorageExension
Storage
end
subgraph StorageCleanerExtension
HTTP_endpoint
end
end
```

# Getting Started

The following settings are required:

- `trace_storage` : name of a storage backend defined in `jaegerstorage` extension

```yaml
extensions:
storage_cleaner:
trace_storage: storage_name
```

18 changes: 18 additions & 0 deletions cmd/jaeger/internal/integration/storagecleaner/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package storagecleaner

import (
"github.com/asaskevich/govalidator"
)

type Config struct {
TraceStorage string `valid:"required" mapstructure:"trace_storage"`
Port string `mapstructure:"port"`
}

func (cfg *Config) Validate() error {
_, err := govalidator.ValidateStruct(cfg)
return err
}
23 changes: 23 additions & 0 deletions cmd/jaeger/internal/integration/storagecleaner/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package storagecleaner

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestStorageExtensionConfig(t *testing.T) {
config := createDefaultConfig().(*Config)
config.TraceStorage = "storage"
err := config.Validate()
require.NoError(t, err)
}

func TestStorageExtensionConfigError(t *testing.T) {
config := createDefaultConfig().(*Config)
err := config.Validate()
require.ErrorContains(t, err, "non zero value required")
}
95 changes: 95 additions & 0 deletions cmd/jaeger/internal/integration/storagecleaner/extension.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package storagecleaner

import (
"context"
"fmt"
"net/http"
"time"

"github.com/gorilla/mux"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"

"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage"
"github.com/jaegertracing/jaeger/storage"
)

var (
_ extension.Extension = (*storageCleaner)(nil)
_ extension.Dependent = (*storageCleaner)(nil)
)

const (
Port = "9231"
URL = "/purge"
)

type storageCleaner struct {
config *Config
server *http.Server
}

func newStorageCleaner(config *Config) *storageCleaner {
return &storageCleaner{
config: config,
}
}

func (c *storageCleaner) Start(ctx context.Context, host component.Host) error {
storageFactory, err := jaegerstorage.GetStorageFactory(c.config.TraceStorage, host)
if err != nil {
return fmt.Errorf("cannot find storage factory for Badger: %w", err)
}

purgeStorage := func() error {
purger, ok := storageFactory.(storage.Purger)
if !ok {
return fmt.Errorf("storage %s does not implement Purger interface", c.config.TraceStorage)
}
if err := purger.Purge(); err != nil {
return fmt.Errorf("error purging Badger storage: %w", err)
}
return nil
}

purgeHandler := func(w http.ResponseWriter, r *http.Request) {
if err := purgeStorage(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("Purge request processed successfully"))
}

r := mux.NewRouter()
r.HandleFunc(URL, purgeHandler).Methods(http.MethodPost)
c.server = &http.Server{
Addr: ":" + c.config.Port,
Handler: r,
ReadHeaderTimeout: 3 * time.Second,
}
go func() error {
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
if err := c.server.ListenAndServe(); err != nil {
return fmt.Errorf("error starting storage cleaner server: %w", err)
}
return nil
}()

return nil
}

func (c *storageCleaner) Shutdown(ctx context.Context) error {
if c.server != nil {
if err := c.server.Shutdown(ctx); err != nil {
return fmt.Errorf("error shutting down cleaner server: %w", err)
}
}
return nil
}

func (c *storageCleaner) Dependencies() []component.ID {
return []component.ID{jaegerstorage.ID}
}
Loading
Loading