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

testing #8

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 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
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

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
80 changes: 80 additions & 0 deletions cmd/jaeger/internal/integration/badger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package integration

import (
"fmt"
"net/http"
"os"
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/zap"

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

type BadgerStorageIntegration struct {
E2EStorageIntegration
logger *zap.Logger
}

func (s *BadgerStorageIntegration) initialize(t *testing.T) {
s.e2eInitialize(t)

s.CleanUp = s.cleanUp
s.logger = zap.NewNop()
}

func (s *BadgerStorageIntegration) cleanUp(t *testing.T) {
Addr := fmt.Sprintf("http://%s:%s%s", "0.0.0.0", 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")

s := &BadgerStorageIntegration{
E2EStorageIntegration: E2EStorageIntegration{
ConfigFile: createBadgerCleanerConfig(t),
StorageIntegration: integration.StorageIntegration{
SkipBinaryAttrs: true,
SkipArchiveTest: true,

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

func createBadgerCleanerConfig(t *testing.T) string {
cmd := exec.Command("../../../../scripts/prepare-badger-integration-tests.py")
data, err := cmd.Output()
require.NoError(t, err)
tempFile := string(data)
tempFile = strings.ReplaceAll(tempFile, "\n", "")
t.Cleanup(func() {
os.Remove(tempFile)
})
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 exposing a HTTP endpoint for making POST requests.

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"| Badger

Badger_e2e_test -->|"(1) POST /purge"| HTTP_endpoint
JaegerStorageExension -->|"(2) getStorage()"| HTTP_endpoint
HTTP_endpoint -.->|"(3) storage.(*Badger).Purge()"| Badger

subgraph Jaeger Collector
Receiver
Processor
Exporter

Badger
BadgerCleanerExtension
HTTP_endpoint
subgraph JaegerStorageExension
Badger
end
subgraph BadgerCleanerExtension
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: external-storage
```

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
}
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 {
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}
}
40 changes: 40 additions & 0 deletions cmd/jaeger/internal/integration/storagecleaner/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package storagecleaner

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"
)

// componentType is the name of this extension in configuration.
var componentType = component.MustNewType("storage_cleaner")

// ID is the identifier of this extension.
var ID = component.NewID(componentType)

func NewFactory() extension.Factory {
return extension.NewFactory(
componentType,
createDefaultConfig,
createExtension,
component.StabilityLevelBeta,
)
}

func createDefaultConfig() component.Config {
return &Config{
Port: Port,
}
}

func createExtension(
_ context.Context,
set extension.CreateSettings,
cfg component.Config,
) (extension.Extension, error) {
return newStorageCleaner(cfg.(*Config)), nil
}
28 changes: 28 additions & 0 deletions cmd/jaeger/internal/integration/storagecleaner/factory_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 storagecleaner

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/extension/extensiontest"
)

func TestCreateDefaultConfig(t *testing.T) {
cfg := createDefaultConfig().(*Config)
require.NotNil(t, cfg, "failed to create default config")
require.NoError(t, componenttest.CheckConfigStruct(cfg))
}

func TestCreateExtension(t *testing.T) {
cfg := createDefaultConfig().(*Config)
f := NewFactory()
r, err := f.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
require.NoError(t, err)
assert.NotNil(t, r)
}
14 changes: 14 additions & 0 deletions cmd/jaeger/internal/integration/storagecleaner/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package storagecleaner

import (
"testing"

"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.VerifyGoLeaks(m)
}
Loading
Loading