Skip to content

Commit

Permalink
tests: open telemetry
Browse files Browse the repository at this point in the history
* add test suite; PASS

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Nov 21, 2024
1 parent 19c5ccb commit b909a1c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions tracing/tracing_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func Shutdown() {
if err := tp.Shutdown(context.Background()); err != nil {
cos.ExitLog(err)
}
tp = nil
}

func NewTraceableHandler(handler http.Handler, operation string) http.Handler {
Expand Down
19 changes: 19 additions & 0 deletions tracing/unit_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Package test provides tests for common low-level types and utilities for all aistore projects
/*
* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
*/
package tracing_test

import (
"testing"

"github.com/NVIDIA/aistore/tools"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestTracing(t *testing.T) {
tools.CheckSkip(t, &tools.SkipTestArgs{Long: true})
RegisterFailHandler(Fail)
RunSpecs(t, t.Name())
}
17 changes: 11 additions & 6 deletions tracing/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
package tracing_test

// usage:
// go test -v -tags="debug oteltracing"

import (
"io"
"net/http"
Expand All @@ -25,8 +28,6 @@ var _ = Describe("Tracing", func() {
const aisVersion = "v3.33"

var (
exporter *tracetest.InMemoryExporter

dummySnode = &meta.Snode{DaeID: "test", DaeType: "proxy"}

newTestHandler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
Expand Down Expand Up @@ -59,11 +60,12 @@ var _ = Describe("Tracing", func() {
tracing.Shutdown()
})
It("should export server trace when tracing enabled", func() {
exporter := tracetest.NewInMemoryExporter()
tracing.Init(&cmn.TracingConf{
ExporterEndpoint: "dummy",
Enabled: true,
SamplerProbability: 1.0,
}, dummySnode, tracetest.NewInMemoryExporter(), aisVersion)
}, dummySnode, exporter, aisVersion)
Expect(tracing.IsEnabled()).To(BeTrue())

server := httptest.NewServer(tracing.NewTraceableHandler(newTestHandler, "testendpoint"))
Expand All @@ -80,9 +82,10 @@ var _ = Describe("Tracing", func() {
})

It("should do nothing when tracing disabled", func() {
exporter := tracetest.NewInMemoryExporter()
tracing.Init(&cmn.TracingConf{
Enabled: false,
}, dummySnode, tracetest.NewInMemoryExporter(), aisVersion)
}, dummySnode, exporter, aisVersion)
Expect(tracing.IsEnabled()).To(BeFalse())

server := httptest.NewServer(tracing.NewTraceableHandler(newTestHandler, "testendpoint"))
Expand All @@ -100,11 +103,12 @@ var _ = Describe("Tracing", func() {
tracing.Shutdown()
})
It("should export client trace when tracing enabled", func() {
exporter := tracetest.NewInMemoryExporter()
tracing.Init(&cmn.TracingConf{
ExporterEndpoint: "dummy",
Enabled: true,
SamplerProbability: 1.0,
}, dummySnode, tracetest.NewInMemoryExporter(), aisVersion)
}, dummySnode, exporter, aisVersion)
Expect(tracing.IsEnabled()).To(BeTrue())

server := httptest.NewServer(newTestHandler)
Expand All @@ -128,9 +132,10 @@ var _ = Describe("Tracing", func() {
})

It("should do nothing when tracing disabled", func() {
exporter := tracetest.NewInMemoryExporter()
tracing.Init(&cmn.TracingConf{
Enabled: false,
}, dummySnode, tracetest.NewInMemoryExporter(), aisVersion)
}, dummySnode, exporter, aisVersion)
Expect(tracing.IsEnabled()).To(BeFalse())

server := httptest.NewServer(newTestHandler)
Expand Down

0 comments on commit b909a1c

Please sign in to comment.