Skip to content

Commit

Permalink
[installer]: add jaeger sampling options to the tracing object
Browse files Browse the repository at this point in the history
This also adds the concept of experimental configuration. Mostly,
this is for unsupported SaaS config or things which are useful when
used in a controlled environment. An experimental feature may be
promoted to the main config or dropped without warning.
  • Loading branch information
Simon Emms committed Jan 25, 2022
1 parent af763f2 commit 8109412
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
18 changes: 16 additions & 2 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 @@ -79,9 +81,21 @@ func TracingEnv(cfg *config.Config) (res []corev1.EnvVar) {
// but would make env var composition more cumbersome.
}

samplerType := experimental.TracingSampleTypeConst
sampleParam := "1"

if cfg.Experimental != nil && cfg.Experimental.Observability != nil && cfg.Experimental.Observability.Tracing != nil {
if st := cfg.Experimental.Observability.Tracing.SamplerType; st != nil {
samplerType = *st
}
if sp := cfg.Experimental.Observability.Tracing.SamplerParam; sp != nil {
sampleParam = strconv.FormatFloat(*sp, 'f', -1, 64)
}
}

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: sampleParam},
)

return
Expand Down
6 changes: 6 additions & 0 deletions installer/pkg/config/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package config

import (
"github.com/gitpod-io/gitpod/installer/pkg/config"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
"github.com/gitpod-io/gitpod/ws-daemon/pkg/resources"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -86,6 +87,11 @@ type Config struct {
License *ObjectRef `json:"license,omitempty"`

SSHGatewayHostKey *ObjectRef `json:"sshGatewayHostKey,omitempty"`

// Anything in here is provided as a convenience, but is entirely unsupported
//
// HERE BE DRAGONS! Enter at your own risk
Experimental *experimental.Config `json:"experimental,omitempty"`
}

type Metadata struct {
Expand Down
28 changes: 28 additions & 0 deletions installer/pkg/config/v1/experimental/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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

type Config struct {
Observability *Observability `json:"observability"`
}

type Observability struct {
Tracing *Tracing `json:"tracing,omitempty"`
}

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

type TracingSampleType string

// 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

0 comments on commit 8109412

Please sign in to comment.