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

feature(backend): adding event logs for otlp endpoints #2427

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
9 changes: 6 additions & 3 deletions server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/kubeshop/tracetest/server/config"
"github.com/kubeshop/tracetest/server/config/configresource"
"github.com/kubeshop/tracetest/server/config/demoresource"
"github.com/kubeshop/tracetest/server/executor"
"github.com/kubeshop/tracetest/server/executor/pollingprofile"
"github.com/kubeshop/tracetest/server/executor/trigger"
httpServer "github.com/kubeshop/tracetest/server/http"
Expand Down Expand Up @@ -187,6 +188,9 @@ func (app *App) Start(opts ...appOption) error {

pollingProfileRepo := pollingprofile.NewRepository(db)

eventEmitter := executor.NewEventEmitter(testDB, subscriptionManager)
registerOtlpServer(app, testDB, eventEmitter)

rf := newRunnerFacades(
pollingProfileRepo,
testDB,
Expand Down Expand Up @@ -225,7 +229,6 @@ func (app *App) Start(opts ...appOption) error {
return err
}

registerOtlpServer(app, testDB)
provisioner := provisioning.New()

router, mappers := controller(app.cfg, testDB, tracer, rf, triggerRegistry)
Expand Down Expand Up @@ -283,8 +286,8 @@ func registerSPAHandler(router *mux.Router, cfg httpServerConfig, analyticsEnabl
)
}

func registerOtlpServer(app *App, testDB model.Repository) {
ingester := otlp.NewIngester(testDB)
func registerOtlpServer(app *App, testDB model.Repository, eventEmitter executor.EventEmitter) {
ingester := otlp.NewIngester(testDB, eventEmitter)
grpcOtlpServer := otlp.NewGrpcServer(":4317", ingester)
httpOtlpServer := otlp.NewHttpServer(":4318", ingester)
go grpcOtlpServer.Start()
Expand Down
15 changes: 15 additions & 0 deletions server/model/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,18 @@ func TestSpecsAssertionWarning(testID id.ID, runID int, err error, spanID string
Outputs: []model.OutputInfo{},
}
}

func TraceOtlpServerReceivedSpans(testID id.ID, runID int, spanCount int) model.TestRunEvent {
return model.TestRunEvent{
TestID: testID,
RunID: runID,
Stage: model.StageTrace,
Type: "OTLP_SERVER_RECEIVED_SPANS",
Title: "OTLP server received spans",
Description: fmt.Sprintf("The Tracetest OTLP server received %d spans", spanCount),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it add any value to include if it was HTTP or GRPC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I just added it to the event

CreatedAt: time.Now(),
DataStoreConnection: model.ConnectionResult{},
Polling: model.PollingInfo{},
Outputs: []model.OutputInfo{},
}
}
11 changes: 8 additions & 3 deletions server/otlp/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ import (
"fmt"
"strings"

"github.com/kubeshop/tracetest/server/executor"
"github.com/kubeshop/tracetest/server/model"
"github.com/kubeshop/tracetest/server/model/events"
"github.com/kubeshop/tracetest/server/traces"
"go.opentelemetry.io/otel/trace"
pb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
v1 "go.opentelemetry.io/proto/otlp/trace/v1"
)

type ingester struct {
db model.Repository
db model.Repository
eventEmitter executor.EventEmitter
}

func NewIngester(db model.Repository) ingester {
func NewIngester(db model.Repository, eventEmitter executor.EventEmitter) ingester {
return ingester{
db: db,
db: db,
eventEmitter: eventEmitter,
}
}

Expand Down Expand Up @@ -104,6 +108,7 @@ func (e ingester) saveSpansIntoTest(ctx context.Context, traceID trace.TraceID,
newSpans := append(existingSpans, spans...)
newTrace := model.NewTrace(traceID.String(), newSpans)

e.eventEmitter.Emit(ctx, events.TraceOtlpServerReceivedSpans(run.TestID, run.ID, len(newSpans)))
run.Trace = &newTrace

err = e.db.UpdateRun(ctx, run)
Expand Down