forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jaeger-v2] Add badger e2e integration test (jaegertracing#5355)
## Which problem is this PR solving? - part of jaegertracing#5254 ## Description of the changes - added badger e2e integration test ## How was this change tested? - tested locally ## 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: Harshvir Potpose <hpotpose62@gmail.com> Signed-off-by: Harshvir Potpose <122517264+akagami-harsh@users.noreply.github.com> Signed-off-by: Yuri Shkuro <github@ysh.us> Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com> Co-authored-by: Yuri Shkuro <github@ysh.us>
- Loading branch information
1 parent
afc4b2f
commit 79cc8a2
Showing
18 changed files
with
524 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
cmd/jaeger/internal/integration/storagecleaner/config_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
98 changes: 98 additions & 0 deletions
98
cmd/jaeger/internal/integration/storagecleaner/extension.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package storagecleaner | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"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 | ||
settings component.TelemetrySettings | ||
} | ||
|
||
func newStorageCleaner(config *Config, telemetrySettings component.TelemetrySettings) *storageCleaner { | ||
return &storageCleaner{ | ||
config: config, | ||
settings: telemetrySettings, | ||
} | ||
} | ||
|
||
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 '%s': %w", c.config.TraceStorage, 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 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() { | ||
if err := c.server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { | ||
err = fmt.Errorf("error starting cleaner server: %w", err) | ||
c.settings.ReportStatus(component.NewFatalErrorEvent(err)) | ||
} | ||
}() | ||
|
||
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} | ||
} |
Oops, something went wrong.