-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: sidecars to inetrface (#443)
* chore: merge main into it * chore: refactor tshark sidecar * fix: tshark test filename * fix: some linters * fix: calling deployResourcesForCommittedState * fix: obsy test nil dereference * fix: added custom image setting for sidecars * chore: after merge fixes * fix: side car set image check with status * fix: linter complains * chore: unittest added to tshark sidecar * chore: added instance check on clone unitttest * fix: unittest for bt & obsy sidecars panic * feat: dont require to add a volume if adding a file Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> * feat: use scope instead of namespace in otlp Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> * feat: avoid using volume in obsy sidecar Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> * fix: otlp config when using not auth Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> * fix: obsy test suceeds now Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> * chore: rename bittwister sidecar * chore: rename bt in ci test * chore: mod tidy after merged main into it * feat: remove commented lines Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> * feat: rename obys to observability Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> * feat: remove not needed func Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> * fix: the failing unittests --------- Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com> Co-authored-by: Smuu <18609909+Smuu@users.noreply.github.com>
- Loading branch information
1 parent
c68be43
commit 0379bca
Showing
32 changed files
with
2,105 additions
and
1,411 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package basic | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/celestiaorg/knuu/pkg/knuu" | ||
"github.com/celestiaorg/knuu/pkg/sidecars/observability" | ||
) | ||
|
||
const ( | ||
prometheusPort = observability.DefaultOtelMetricsPort | ||
prometheusImage = "prom/prometheus:latest" | ||
prometheusConfig = "/etc/prometheus/prometheus.yml" | ||
prometheusArgs = "--config.file=/etc/prometheus/prometheus.yml" | ||
|
||
targetImage = "curlimages/curl:latest" | ||
otlpPort = observability.DefaultOtelOtlpPort | ||
) | ||
|
||
// TestObservabilityCollector is a test function that verifies the functionality of the otel collector setup | ||
func TestObservabilityCollector(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Setup Prometheus | ||
prometheus, err := knuu.NewInstance("prometheus") | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, prometheus.SetImage(prometheusImage)) | ||
require.NoError(t, prometheus.AddPortTCP(prometheusPort)) | ||
|
||
// enable proxy for this port | ||
err, prometheusEndpoint := prometheus.AddHost(prometheusPort) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, prometheus.Commit()) | ||
|
||
// Add Prometheus config file | ||
prometheusConfigContent := fmt.Sprintf(` | ||
global: | ||
scrape_interval: '10s' | ||
scrape_configs: | ||
- job_name: 'otel-collector' | ||
static_configs: | ||
- targets: ['otel-collector:%d'] | ||
`, otlpPort) | ||
require.NoError(t, prometheus.AddFileBytes([]byte(prometheusConfigContent), prometheusConfig, "0:0")) | ||
|
||
require.NoError(t, prometheus.SetArgs(prometheusArgs)) | ||
require.NoError(t, prometheus.Start()) | ||
|
||
// Setup observabilitySidecar collector | ||
observabilitySidecar := observability.New() | ||
|
||
require.NoError(t, observabilitySidecar.SetOtelEndpoint(4318)) | ||
|
||
err = observabilitySidecar.SetPrometheusEndpoint(otlpPort, fmt.Sprintf("knuu-%s", knuu.Scope()), "10s") | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, observabilitySidecar.SetJaegerEndpoint(14250, 6831, 14268)) | ||
|
||
require.NoError(t, observabilitySidecar.SetOtlpExporter("prometheus:9090", "", "")) | ||
|
||
// Create and start a target pod and configure it to use the obsySidecar to push metrics | ||
target, err := knuu.NewInstance("target") | ||
require.NoError(t, err, "Error creating target instance") | ||
|
||
err = target.SetImage(targetImage) | ||
require.NoError(t, err, "Error setting target image") | ||
|
||
err = target.SetCommand("sh", "-c", "while true; do curl -X POST http://localhost:8888/v1/traces; sleep 5; done") | ||
require.NoError(t, err, "Error setting target command") | ||
|
||
require.NoError(t, target.AddSidecar(context.Background(), observabilitySidecar)) | ||
|
||
require.NoError(t, target.Commit(), "Error committing target instance") | ||
|
||
require.NoError(t, target.Start(), "Error starting target instance") | ||
|
||
t.Cleanup(func() { | ||
if os.Getenv("KNUU_SKIP_CLEANUP") == "true" { | ||
t.Log("Skipping cleanup") | ||
return | ||
} | ||
err := knuu.BatchDestroy(prometheus, target) | ||
if err != nil { | ||
t.Log("Error destroying instances: ", err) | ||
} | ||
}) | ||
|
||
// Wait for the target pod to push data to the otel collector | ||
time.Sleep(1 * time.Minute) | ||
|
||
// Verify that data has been pushed to Prometheus | ||
|
||
prometheusURL := fmt.Sprintf("%s/api/v1/query?query=up", prometheusEndpoint) | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cancel() | ||
|
||
req, err := http.NewRequestWithContext(ctx, "GET", prometheusURL, nil) | ||
require.NoError(t, err) | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
require.NoError(t, err) | ||
require.Equal(t, 200, resp.StatusCode, "Prometheus API is not accessible") | ||
|
||
defer resp.Body.Close() | ||
body, err := ioutil.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
require.Contains(t, string(body), "otel-collector", "otel-collector data source not found in Prometheus") | ||
|
||
t.Log("otel-collector data source is available in Prometheus") | ||
} |
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
2 changes: 1 addition & 1 deletion
2
e2e/bittwister/suite_setup_test.go → e2e/netshaper/suite_setup_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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package bittwister | ||
package netshaper | ||
|
||
import ( | ||
"context" | ||
|
Oops, something went wrong.