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

feat(server): add options for test pipeline #3161

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func (app *App) Start(opts ...appOption) error {
subscriptionManager,
triggerRegistry,
tracedbFactory,
app.cfg,
)
testPipeline.Start()
app.registerStopFn(func() {
Expand Down
6 changes: 5 additions & 1 deletion server/app/test_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"github.com/jackc/pgx/v5/pgxpool"
"github.com/kubeshop/tracetest/server/config"
"github.com/kubeshop/tracetest/server/datastore"
"github.com/kubeshop/tracetest/server/executor"
"github.com/kubeshop/tracetest/server/executor/pollingprofile"
Expand Down Expand Up @@ -30,6 +31,7 @@ func buildTestPipeline(
subscriptionManager *subscription.Manager,
triggerRegistry *trigger.Registry,
tracedbFactory tracedb.FactoryFunc,
appConfig *config.AppConfig,
) *executor.TestPipeline {
eventEmitter := executor.NewEventEmitter(treRepo, subscriptionManager)

Expand All @@ -45,7 +47,7 @@ func buildTestPipeline(
eventEmitter,
)

linterRunner := executor.NewlinterRunner(
linterRunner := executor.NewLinterRunner(
execTestUpdater,
subscriptionManager,
eventEmitter,
Expand All @@ -68,6 +70,7 @@ func buildTestPipeline(
execTestUpdater,
subscriptionManager,
tracer,
appConfig.TestPipelineTraceFetchingEnabled(),
)

tracePollerEvaluatorWorker := tracepollerworker.NewEvaluatorWorker(
Expand All @@ -94,6 +97,7 @@ func buildTestPipeline(
execTestUpdater,
tracer,
eventEmitter,
appConfig.TestPipelineTriggerExecutionEnabled(),
)

triggerResultProcessorWorker := executor.NewTriggerResultProcessorWorker(
Expand Down
27 changes: 27 additions & 0 deletions server/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ var serverOptions = options{
description: "internal telemetry otel collector (used for internal testing)",
validate: nil,
},
{
key: "testPipelines.triggerExecute.enabled",
defaultValue: "true",
description: "enable local trigger execution",
},
{
key: "testPipelines.traceFetch.enabled",
defaultValue: "true",
description: "enable local trace fetching",
},
}

func init() {
Expand Down Expand Up @@ -130,3 +140,20 @@ func (c *AppConfig) InternalTelemetryOtelCollectorAddress() string {

return c.vp.GetString("internalTelemetry.otelCollectorEndpoint")
}

func (c *AppConfig) TestPipelineTriggerExecutionEnabled() bool {
c.mu.Lock()
defer c.mu.Unlock()

// this config needs to be a string because pflags
// has a strage bug that ignores this field when
// it is set as false
return c.vp.GetString("testPipelines.triggerExecute.enabled") == "true"
}

func (c *AppConfig) TestPipelineTraceFetchingEnabled() bool {
c.mu.Lock()
defer c.mu.Unlock()

return c.vp.GetString("testPipelines.traceFetch.enabled") == "true"
}
13 changes: 13 additions & 0 deletions server/config/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func TestServerConfig(t *testing.T) {

assert.Equal(t, false, cfg.InternalTelemetryEnabled())
assert.Equal(t, "", cfg.InternalTelemetryOtelCollectorAddress())

assert.Equal(t, true, cfg.TestPipelineTriggerExecutionEnabled())
assert.Equal(t, true, cfg.TestPipelineTraceFetchingEnabled())
})

t.Run("Flags", func(t *testing.T) {
Expand All @@ -36,6 +39,8 @@ func TestServerConfig(t *testing.T) {
"--experimentalFeatures", "b",
"--internalTelemetry.enabled", "true",
"--internalTelemetry.otelCollectorEndpoint", "otel-collector.tracetest",
"--testPipelines.triggerExecute.enabled", "false",
"--testPipelines.traceFetch.enabled", "false",
}

cfg := configWithFlags(t, flags)
Expand All @@ -49,6 +54,9 @@ func TestServerConfig(t *testing.T) {

assert.Equal(t, true, cfg.InternalTelemetryEnabled())
assert.Equal(t, "otel-collector.tracetest", cfg.InternalTelemetryOtelCollectorAddress())

assert.Equal(t, false, cfg.TestPipelineTriggerExecutionEnabled())
assert.Equal(t, false, cfg.TestPipelineTraceFetchingEnabled())
})

t.Run("EnvVars", func(t *testing.T) {
Expand All @@ -64,6 +72,8 @@ func TestServerConfig(t *testing.T) {
"TRACETEST_EXPERIMENTALFEATURES": "a b",
"TRACETEST_INTERNALTELEMETRY_ENABLED": "true",
"TRACETEST_INTERNALTELEMETRY_OTELCOLLECTORENDPOINT": "otel-collector.tracetest",
"TRACETEST_TESTPIPELINES_TRIGGEREXECUTE_ENABLED": "false",
"TRACETEST_TESTPIPELINES_TRACEFETCH_ENABLED": "false",
}

cfg := configWithEnv(t, env)
Expand All @@ -77,5 +87,8 @@ func TestServerConfig(t *testing.T) {

assert.Equal(t, true, cfg.InternalTelemetryEnabled())
assert.Equal(t, "otel-collector.tracetest", cfg.InternalTelemetryOtelCollectorAddress())

assert.Equal(t, false, cfg.TestPipelineTriggerExecutionEnabled())
assert.Equal(t, false, cfg.TestPipelineTraceFetchingEnabled())
})
}
2 changes: 1 addition & 1 deletion server/executor/linter_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type defaultLinterRunner struct {
outputQueue pipeline.Enqueuer[Job]
}

func NewlinterRunner(
func NewLinterRunner(
updater RunUpdater,
subscriptionManager *subscription.Manager,
eventEmitter EventEmitter,
Expand Down
8 changes: 7 additions & 1 deletion server/executor/tracepollerworker/fetcher_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
type traceFetcherWorker struct {
state *workerState
outputQueue pipeline.Enqueuer[executor.Job]
enabled bool
}

func NewFetcherWorker(
Expand All @@ -25,6 +26,7 @@ func NewFetcherWorker(
updater executor.RunUpdater,
subscriptionManager *subscription.Manager,
tracer trace.Tracer,
enabled bool,
) *traceFetcherWorker {
state := &workerState{
eventEmitter: eventEmitter,
Expand All @@ -35,7 +37,7 @@ func NewFetcherWorker(
tracer: tracer,
}

return &traceFetcherWorker{state: state}
return &traceFetcherWorker{state: state, enabled: enabled}
}

func (w *traceFetcherWorker) SetInputQueue(queue pipeline.Enqueuer[executor.Job]) {
Expand All @@ -47,6 +49,10 @@ func (w *traceFetcherWorker) SetOutputQueue(queue pipeline.Enqueuer[executor.Job
}

func (w *traceFetcherWorker) ProcessItem(ctx context.Context, job executor.Job) {
if !w.enabled {
return
}

ctx, span := w.state.tracer.Start(ctx, "Fetching trace")
defer span.End()

Expand Down
7 changes: 7 additions & 0 deletions server/executor/trigger_executer_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ func NewTriggerExecuterWorker(
updater RunUpdater,
tracer trace.Tracer,
eventEmitter EventEmitter,
enabled bool,
) *triggerExecuterWorker {
return &triggerExecuterWorker{
triggers: triggers,
updater: updater,
tracer: tracer,
eventEmitter: eventEmitter,
enabled: enabled,
}
}

Expand All @@ -36,6 +38,7 @@ type triggerExecuterWorker struct {
tracer trace.Tracer
eventEmitter EventEmitter
outputQueue pipeline.Enqueuer[Job]
enabled bool
}

func (r *triggerExecuterWorker) SetOutputQueue(queue pipeline.Enqueuer[Job]) {
Expand All @@ -55,6 +58,10 @@ func (r triggerExecuterWorker) handleError(run test.Run, err error) {
}

func (r triggerExecuterWorker) ProcessItem(ctx context.Context, job Job) {
if !r.enabled {
return
}

err := r.eventEmitter.Emit(ctx, events.TriggerExecutionStart(job.Run.TestID, job.Run.ID))
if err != nil {
r.handleError(job.Run, err)
Expand Down
Loading