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

[installer] Separate webapp tracing config from workspace tracing config #9900

Merged
merged 5 commits into from
May 11, 2022
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
45 changes: 34 additions & 11 deletions install/installer/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,33 @@ func DefaultEnv(cfg *config.Config) []corev1.EnvVar {
}
}

func TracingEnv(context *RenderContext) (res []corev1.EnvVar) {
func WorkspaceTracingEnv(context *RenderContext) (res []corev1.EnvVar) {
var tracing *experimental.Tracing

_ = context.WithExperimental(func(cfg *experimental.Config) error {
if cfg.Workspace != nil {
tracing = cfg.Workspace.Tracing
}
return nil
})

return tracingEnv(context, tracing)
}

func WebappTracingEnv(context *RenderContext) (res []corev1.EnvVar) {
var tracing *experimental.Tracing

_ = context.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil {
tracing = cfg.WebApp.Tracing
}
return nil
})

return tracingEnv(context, tracing)
}

func tracingEnv(context *RenderContext, tracing *experimental.Tracing) (res []corev1.EnvVar) {
if context.Config.Observability.Tracing == nil {
res = append(res, corev1.EnvVar{Name: "JAEGER_DISABLED", Value: "true"})
return
Expand All @@ -81,17 +107,14 @@ func TracingEnv(context *RenderContext) (res []corev1.EnvVar) {
samplerType := experimental.TracingSampleTypeConst
samplerParam := "1"

_ = context.WithExperimental(func(ucfg *experimental.Config) error {
if ucfg.Workspace != nil && ucfg.Workspace.Tracing != nil {
if ucfg.Workspace.Tracing.SamplerType != nil {
samplerType = *ucfg.Workspace.Tracing.SamplerType
}
if ucfg.Workspace.Tracing.SamplerParam != nil {
samplerParam = strconv.FormatFloat(*ucfg.Workspace.Tracing.SamplerParam, 'f', -1, 64)
}
if tracing != nil {
if tracing.SamplerType != nil {
samplerType = *tracing.SamplerType
}
return nil
})
if tracing.SamplerParam != nil {
samplerParam = strconv.FormatFloat(*tracing.SamplerParam, 'f', -1, 64)
}
}

res = append(res,
corev1.EnvVar{Name: "JAEGER_SAMPLER_TYPE", Value: string(samplerType)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func daemonset(ctx *common.RenderContext) ([]runtime.Object, error) {
}},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
[]corev1.EnvVar{{
Name: "NODENAME",
ValueFrom: &corev1.EnvVarSource{
Expand Down
2 changes: 1 addition & 1 deletion install/installer/pkg/components/blobserve/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
),
VolumeMounts: []corev1.VolumeMount{{
Name: "config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
[]corev1.EnvVar{{
Name: "GRPC_GO_RETRY",
Value: "on",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
),
Resources: common.ResourceRequirements(ctx, Component, Component, corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func daemonset(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
[]corev1.EnvVar{
{
Name: "GRPC_GO_RETRY",
Expand Down
2 changes: 1 addition & 1 deletion install/installer/pkg/components/server/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
env := common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.DatabaseEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WebappTracingEnv(ctx),
common.AnalyticsEnv(&ctx.Config),
common.MessageBusEnv(&ctx.Config),
[]corev1.EnvVar{
Expand Down
37 changes: 37 additions & 0 deletions install/installer/pkg/components/server/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,50 @@ func TestServerDeployment_MountsGithubAppSecret(t *testing.T) {
require.Truef(t, foundMount, "failed to find expected volume mount %q on server container", githubAppCertSecret)
}

func TestServerDeployment_UsesTracingConfig(t *testing.T) {
ctx := renderContext(t)

objects, err := deployment(ctx)
require.NoError(t, err)

require.Len(t, objects, 1, "must render only one object")

deployment := objects[0].(*appsv1.Deployment)

serverContainer := deployment.Spec.Template.Spec.Containers[0]

var envVars = make(map[string]string, len(serverContainer.Env))
for _, envVar := range serverContainer.Env {
envVars[envVar.Name] = envVar.Value
}

actualSamplerType := envVars["JAEGER_SAMPLER_TYPE"]
actualSamplerParam := envVars["JAEGER_SAMPLER_PARAM"]

require.Equal(t, "probabilistic", actualSamplerType)
require.Equal(t, "12.5", actualSamplerParam)
}

func renderContext(t *testing.T) *common.RenderContext {
var samplerType experimental.TracingSampleType = "probabilistic"

ctx, err := common.NewRenderContext(config.Config{
Database: config.Database{
InCluster: pointer.Bool(true),
},
Observability: config.Observability{
LogLevel: config.LogLevelInfo,
Tracing: &config.Tracing{
Endpoint: pointer.String("some-endpoint"),
AgentHost: pointer.String("some-agent-host"),
},
},
Experimental: &experimental.Config{
WebApp: &experimental.WebAppConfig{
Tracing: &experimental.Tracing{
SamplerType: &samplerType,
SamplerParam: pointer.Float64(12.5),
},
Server: &experimental.ServerConfig{
GithubApp: &experimental.GithubApp{
AppId: 0,
Expand Down
2 changes: 1 addition & 1 deletion install/installer/pkg/components/ws-daemon/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fi
}},
Env: common.MergeEnv(
common.DefaultEnv(&cfg),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
[]corev1.EnvVar{{
Name: "NODENAME",
ValueFrom: &corev1.EnvVarSource{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
common.AnalyticsEnv(&ctx.Config),
common.MessageBusEnv(&ctx.Config),
common.DatabaseEnv(&ctx.Config),
Expand Down
2 changes: 1 addition & 1 deletion install/installer/pkg/components/ws-manager/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
[]corev1.EnvVar{{Name: "GRPC_GO_RETRY", Value: "on"}},
),
VolumeMounts: []corev1.VolumeMount{
Expand Down
2 changes: 1 addition & 1 deletion install/installer/pkg/components/ws-proxy/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(ctx),
common.WorkspaceTracingEnv(ctx),
),
ReadinessProbe: &corev1.Probe{
InitialDelaySeconds: int32(2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type WebAppConfig struct {
Server *ServerConfig `json:"server,omitempty"`
ProxyConfig *ProxyConfig `json:"proxy,omitempty"`
WorkspaceManagerBridge *WsManagerBridgeConfig `json:"wsManagerBridge,omitempty"`
Tracing *Tracing `json:"tracing,omitempty"`
UsePodAntiAffinity bool `json:"usePodAntiAffinity"`
DisableMigration bool `json:"disableMigration"`
}
Expand Down