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]: add jaeger sampling options to the tracing object #7727

Merged
merged 1 commit into from
Feb 2, 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
29 changes: 23 additions & 6 deletions installer/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"fmt"
"io"
"math/rand"
"strconv"
"strings"

wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
config "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"

"github.com/docker/distribution/reference"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -64,24 +66,39 @@ func DefaultEnv(cfg *config.Config) []corev1.EnvVar {
}
}

func TracingEnv(cfg *config.Config) (res []corev1.EnvVar) {
if cfg.Observability.Tracing == nil {
func TracingEnv(context *RenderContext) (res []corev1.EnvVar) {
if context.Config.Observability.Tracing == nil {
return
}

if ep := cfg.Observability.Tracing.Endpoint; ep != nil {
if ep := context.Config.Observability.Tracing.Endpoint; ep != nil {
res = append(res, corev1.EnvVar{Name: "JAEGER_ENDPOINT", Value: *ep})
} else if v := cfg.Observability.Tracing.AgentHost; v != nil {
} else if v := context.Config.Observability.Tracing.AgentHost; v != nil {
res = append(res, corev1.EnvVar{Name: "JAEGER_AGENT_HOST", Value: *v})
} else {
// TODO(cw): think about proper error handling here.
// Returning an error would be the appropriate thing to do,
// but would make env var composition more cumbersome.
}

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)
}
}
return nil
})

res = append(res,
corev1.EnvVar{Name: "JAEGER_SAMPLER_TYPE", Value: "const"},
corev1.EnvVar{Name: "JAEGER_SAMPLER_PARAM", Value: "1"},
corev1.EnvVar{Name: "JAEGER_SAMPLER_TYPE", Value: string(samplerType)},
corev1.EnvVar{Name: "JAEGER_SAMPLER_PARAM", Value: samplerParam},
)

return
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/agent-smith/daemonset.go
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.Config),
common.TracingEnv(ctx),
[]corev1.EnvVar{{
Name: "NODENAME",
ValueFrom: &corev1.EnvVarSource{
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/blobserve/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(&ctx.Config),
common.TracingEnv(ctx),
),
VolumeMounts: []corev1.VolumeMount{{
Name: "config",
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/content-service/deployment.go
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.Config),
common.TracingEnv(ctx),
[]corev1.EnvVar{{
Name: "GRPC_GO_RETRY",
Value: "on",
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/image-builder-mk3/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(&ctx.Config),
common.TracingEnv(ctx),
),
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/registry-facade/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func daemonset(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(&ctx.Config),
common.TracingEnv(ctx),
[]corev1.EnvVar{{
Name: "GRPC_GO_RETRY",
Value: "on",
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/server/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.DatabaseEnv(&ctx.Config),
common.TracingEnv(&ctx.Config),
common.TracingEnv(ctx),
common.AnalyticsEnv(&ctx.Config),
common.MessageBusEnv(&ctx.Config),
[]corev1.EnvVar{{
Expand Down
2 changes: 1 addition & 1 deletion 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(&cfg),
common.TracingEnv(ctx),
[]corev1.EnvVar{{
Name: "NODENAME",
ValueFrom: &corev1.EnvVarSource{
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/ws-manager-bridge/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(&ctx.Config),
common.TracingEnv(ctx),
common.AnalyticsEnv(&ctx.Config),
common.MessageBusEnv(&ctx.Config),
common.DatabaseEnv(&ctx.Config),
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/ws-manager/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(&ctx.Config),
common.TracingEnv(ctx),
[]corev1.EnvVar{{Name: "GRPC_GO_RETRY", Value: "on"}},
),
VolumeMounts: []corev1.VolumeMount{{
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/components/ws-proxy/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
Env: common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.TracingEnv(&ctx.Config),
common.TracingEnv(ctx),
),
ReadinessProbe: &corev1.Probe{
InitialDelaySeconds: int32(2),
Expand Down
18 changes: 17 additions & 1 deletion installer/pkg/config/v1/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@ type Config struct {
}

type WorkspaceConfig struct {
Stage string `json:"stage"`
Tracing *Tracing `json:"tracing"`
Stage string `json:"stage"`
}

type WebAppConfig struct {
}

type IDEConfig struct{}

type TracingSampleType string

type Tracing struct {
SamplerType *TracingSampleType `json:"samplerType,omitempty" validate:"omitempty,tracing_sampler_type"`
SamplerParam *float64 `json:"samplerParam,omitEmpty" validate:"required_with=SamplerType"`
}

// Values taken from https://github.com/jaegertracing/jaeger-client-go/blob/967f9c36f0fa5a2617c9a0993b03f9a3279fadc8/config/config.go#L71
const (
TracingSampleTypeConst TracingSampleType = "const"
TracingSampleTypeProbabilistic TracingSampleType = "probabilistic"
TracingSampleTypeRateLimiting TracingSampleType = "rateLimiting"
TracingSampleTypeRemote TracingSampleType = "remote"
)
21 changes: 21 additions & 0 deletions installer/pkg/config/v1/experimental/validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package experimental

import "github.com/go-playground/validator/v10"

var TracingSampleTypeList = map[TracingSampleType]struct{}{
TracingSampleTypeConst: {},
TracingSampleTypeProbabilistic: {},
TracingSampleTypeRateLimiting: {},
TracingSampleTypeRemote: {},
}

var ValidationChecks = map[string]validator.Func{
"tracing_sampler_type": func(fl validator.FieldLevel) bool {
_, ok := TracingSampleTypeList[TracingSampleType(fl.Field().String())]
return ok
},
}
6 changes: 6 additions & 0 deletions installer/pkg/config/v1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

"github.com/gitpod-io/gitpod/installer/pkg/cluster"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
"golang.org/x/crypto/ssh"
"sigs.k8s.io/yaml"

Expand Down Expand Up @@ -60,6 +61,11 @@ func (v version) LoadValidationFuncs(validate *validator.Validate) error {
return ok
},
}

for k, v := range experimental.ValidationChecks {
funcs[k] = v
}

for n, f := range funcs {
err := validate.RegisterValidation(n, f)
if err != nil {
Expand Down