Skip to content

Commit

Permalink
Make configurable availability of the service names in Tempo monolith…
Browse files Browse the repository at this point in the history
…ic (#941)

* Make configurable availability of the service names in Tempo monolithic

Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 authored May 23, 2024
1 parent ffba836 commit fff4c20
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 25 deletions.
16 changes: 16 additions & 0 deletions .chloggen/monolithic_services_duration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. operator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Make configurable availability of the service names in Tempo monolithic

# One or more tracking issues related to the change
issues: [942]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
44 changes: 26 additions & 18 deletions apis/tempo/v1alpha1/tempomonolithic_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package v1alpha1
import (
"fmt"
"strings"
"time"

"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

configv1alpha1 "github.com/grafana/tempo-operator/apis/config/v1alpha1"
)

var (
twoGBQuantity = resource.MustParse("2Gi")
tenGBQuantity = resource.MustParse("10Gi")
twoGBQuantity = resource.MustParse("2Gi")
tenGBQuantity = resource.MustParse("10Gi")
defaultServicesDuration = metav1.Duration{Duration: time.Hour * 24 * 3}
)

// Default sets all default values in a central place, instead of setting it at every place where the value is accessed.
Expand Down Expand Up @@ -56,28 +59,33 @@ func (r *TempoMonolithic) Default(ctrlConfig configv1alpha1.ProjectConfig) {
Enabled: true,
}
}
if r.Spec.JaegerUI != nil && r.Spec.JaegerUI.Enabled &&
r.Spec.JaegerUI.Route != nil && r.Spec.JaegerUI.Route.Enabled {
if r.Spec.JaegerUI != nil && r.Spec.JaegerUI.Enabled {

if r.Spec.JaegerUI.Route.Termination == "" {
if r.Spec.Multitenancy.IsGatewayEnabled() && ctrlConfig.Gates.OpenShift.ServingCertsService {
// gateway uses TLS
r.Spec.JaegerUI.Route.Termination = TLSRouteTerminationTypePassthrough
} else {
r.Spec.JaegerUI.Route.Termination = TLSRouteTerminationTypeEdge
if r.Spec.JaegerUI.Route != nil && r.Spec.JaegerUI.Route.Enabled {

if r.Spec.JaegerUI.Route.Termination == "" {
if r.Spec.Multitenancy.IsGatewayEnabled() && ctrlConfig.Gates.OpenShift.ServingCertsService {
// gateway uses TLS
r.Spec.JaegerUI.Route.Termination = TLSRouteTerminationTypePassthrough
} else {
r.Spec.JaegerUI.Route.Termination = TLSRouteTerminationTypeEdge
}
}
}

if r.Spec.JaegerUI.Authentication == nil {
r.Spec.JaegerUI.Authentication = &JaegerQueryAuthenticationSpec{
Enabled: ctrlConfig.Gates.OpenShift.OauthProxy.DefaultEnabled,
if r.Spec.JaegerUI.Authentication == nil {
r.Spec.JaegerUI.Authentication = &JaegerQueryAuthenticationSpec{
Enabled: ctrlConfig.Gates.OpenShift.OauthProxy.DefaultEnabled,
}
}
}

if len(strings.TrimSpace(r.Spec.JaegerUI.Authentication.SAR)) == 0 {
defaultSAR := fmt.Sprintf("{\"namespace\": \"%s\", \"resource\": \"pods\", \"verb\": \"get\"}", r.Namespace)
r.Spec.JaegerUI.Authentication.SAR = defaultSAR
if len(strings.TrimSpace(r.Spec.JaegerUI.Authentication.SAR)) == 0 {
defaultSAR := fmt.Sprintf("{\"namespace\": \"%s\", \"resource\": \"pods\", \"verb\": \"get\"}", r.Namespace)
r.Spec.JaegerUI.Authentication.SAR = defaultSAR
}
}

if r.Spec.JaegerUI.ServicesQueryDuration == nil {
r.Spec.JaegerUI.ServicesQueryDuration = &defaultServicesDuration
}
}
}
66 changes: 66 additions & 0 deletions apis/tempo/v1alpha1/tempomonolithic_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -190,6 +191,7 @@ func TestMonolithicDefault(t *testing.T) {
Enabled: true,
SAR: "{\"namespace\": \"testns\", \"resource\": \"pods\", \"verb\": \"get\"}",
},
ServicesQueryDuration: &defaultServicesDuration,
},
Management: "Managed",
},
Expand Down Expand Up @@ -261,6 +263,7 @@ func TestMonolithicDefault(t *testing.T) {
Enabled: false,
SAR: "{\"namespace\": \"testns\", \"resource\": \"pods\", \"verb\": \"get\"}",
},
ServicesQueryDuration: &defaultServicesDuration,
},
Management: "Managed",
},
Expand Down Expand Up @@ -324,6 +327,7 @@ func TestMonolithicDefault(t *testing.T) {
Enabled: true,
SAR: "{\"namespace\": \"testns\", \"resource\": \"pods\", \"verb\": \"get\"}",
},
ServicesQueryDuration: &defaultServicesDuration,
},
Management: "Managed",
},
Expand Down Expand Up @@ -386,6 +390,68 @@ func TestMonolithicDefault(t *testing.T) {
Enabled: false,
SAR: "{\"namespace\": \"testns\", \"resource\": \"pods\", \"verb\": \"get\"}",
},
ServicesQueryDuration: &defaultServicesDuration,
},
Management: "Managed",
},
},
},
{
name: "define custom duration for services list",
input: &TempoMonolithic{
ObjectMeta: v1.ObjectMeta{
Name: "test",
Namespace: "testns",
},
Spec: TempoMonolithicSpec{
Storage: &MonolithicStorageSpec{
Traces: MonolithicTracesStorageSpec{
Backend: "s3",
Size: &twentyGBQuantity,
},
},
JaegerUI: &MonolithicJaegerUISpec{
Enabled: true,
Route: &MonolithicJaegerUIRouteSpec{
Enabled: true,
},
ServicesQueryDuration: &v1.Duration{Duration: time.Duration(100 * 100)},
},
},
},
expected: &TempoMonolithic{
ObjectMeta: v1.ObjectMeta{
Name: "test",
Namespace: "testns",
},
Spec: TempoMonolithicSpec{
Storage: &MonolithicStorageSpec{
Traces: MonolithicTracesStorageSpec{
Backend: "s3",
Size: &twentyGBQuantity,
},
},
Ingestion: &MonolithicIngestionSpec{
OTLP: &MonolithicIngestionOTLPSpec{
GRPC: &MonolithicIngestionOTLPProtocolsGRPCSpec{
Enabled: true,
},
HTTP: &MonolithicIngestionOTLPProtocolsHTTPSpec{
Enabled: true,
},
},
},
JaegerUI: &MonolithicJaegerUISpec{
Enabled: true,
Route: &MonolithicJaegerUIRouteSpec{
Enabled: true,
Termination: TLSRouteTerminationTypeEdge,
},
Authentication: &JaegerQueryAuthenticationSpec{
Enabled: false,
SAR: "{\"namespace\": \"testns\", \"resource\": \"pods\", \"verb\": \"get\"}",
},
ServicesQueryDuration: &v1.Duration{Duration: time.Duration(100 * 100)},
},
Management: "Managed",
},
Expand Down
6 changes: 6 additions & 0 deletions apis/tempo/v1alpha1/tempomonolithic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ type MonolithicJaegerUISpec struct {
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Jaeger UI authentication configuration",order=5
Authentication *JaegerQueryAuthenticationSpec `json:"authentication,omitempty"`

// ServicesQueryDuration defines how long the services will be available in the services list
//
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="ServicesQueryDuration",xDescriptors="urn:alm:descriptor:com.tectonic.ui:advanced"
ServicesQueryDuration *metav1.Duration `json:"servicesQueryDuration,omitempty"`
}

// MonolithicJaegerUIIngressSpec defines the settings for the Jaeger UI ingress.
Expand Down
5 changes: 5 additions & 0 deletions apis/tempo/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ metadata:
capabilities: Deep Insights
categories: Logging & Tracing,Monitoring
containerImage: ghcr.io/grafana/tempo-operator/tempo-operator:v0.10.0
createdAt: "2024-05-13T02:30:00Z"
createdAt: "2024-05-23T12:54:48Z"
description: Create and manage deployments of Tempo, a high-scale distributed
tracing backend.
operatorframework.io/cluster-monitoring: "true"
Expand Down Expand Up @@ -320,6 +320,12 @@ spec:
- description: Termination specifies the termination type.
displayName: TLS Termination
path: jaegerui.route.termination
- description: ServicesQueryDuration defines how long the services will be available
in the services list
displayName: ServicesQueryDuration
path: jaegerui.servicesQueryDuration
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- description: 'ManagementState defines whether this instance is managed by
the operator or self-managed. Default: Managed.'
displayName: Management State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,10 @@ spec:
required:
- enabled
type: object
servicesQueryDuration:
description: ServicesQueryDuration defines how long the services
will be available in the services list
type: string
required:
- enabled
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ metadata:
capabilities: Deep Insights
categories: Logging & Tracing,Monitoring
containerImage: ghcr.io/grafana/tempo-operator/tempo-operator:v0.10.0
createdAt: "2024-05-13T02:29:58Z"
createdAt: "2024-05-23T12:54:46Z"
description: Create and manage deployments of Tempo, a high-scale distributed
tracing backend.
operatorframework.io/cluster-monitoring: "true"
Expand Down Expand Up @@ -320,6 +320,12 @@ spec:
- description: Termination specifies the termination type.
displayName: TLS Termination
path: jaegerui.route.termination
- description: ServicesQueryDuration defines how long the services will be available
in the services list
displayName: ServicesQueryDuration
path: jaegerui.servicesQueryDuration
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- description: 'ManagementState defines whether this instance is managed by
the operator or self-managed. Default: Managed.'
displayName: Management State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,10 @@ spec:
required:
- enabled
type: object
servicesQueryDuration:
description: ServicesQueryDuration defines how long the services
will be available in the services list
type: string
required:
- enabled
type: object
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/tempo.grafana.com_tempomonolithics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,10 @@ spec:
required:
- enabled
type: object
servicesQueryDuration:
description: ServicesQueryDuration defines how long the services
will be available in the services list
type: string
required:
- enabled
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ spec:
- description: Termination specifies the termination type.
displayName: TLS Termination
path: jaegerui.route.termination
- description: ServicesQueryDuration defines how long the services will be available
in the services list
displayName: ServicesQueryDuration
path: jaegerui.servicesQueryDuration
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- description: 'ManagementState defines whether this instance is managed by
the operator or self-managed. Default: Managed.'
displayName: Management State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ spec:
- description: Termination specifies the termination type.
displayName: TLS Termination
path: jaegerui.route.termination
- description: ServicesQueryDuration defines how long the services will be available
in the services list
displayName: ServicesQueryDuration
path: jaegerui.servicesQueryDuration
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- description: 'ManagementState defines whether this instance is managed by
the operator or self-managed. Default: Managed.'
displayName: Management State
Expand Down
1 change: 1 addition & 0 deletions docs/spec/tempo.grafana.com_tempomonolithics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ spec: # TempoMonolithicSpec defines the desir
annotations: {} # Annotations defines the annotations of the Route object.
host: "" # Host defines the hostname of the Route object.
termination: "" # Termination specifies the termination type.
servicesQueryDuration: "" # ServicesQueryDuration defines how long the services will be available in the services list
resources: # Resources defines the compute resource requirements of the Jaeger UI container.
claims: # Claims lists the names of resources, defined in spec.resourceClaims, that are used by this container. This is an alpha field and requires enabling the DynamicResourceAllocation feature gate. This field is immutable. It can only be set for containers.
- name: "" # Name must match the name of one entry in pod.spec.resourceClaims of the Pod where this field is used. It makes that resource available inside a container.
Expand Down
12 changes: 7 additions & 5 deletions internal/manifests/monolithic/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha256"
"fmt"
"path"
"time"

"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -93,8 +94,9 @@ type tempoConfig struct {
}

type tempoQueryConfig struct {
Backend string `yaml:"backend"`
TenantHeaderKey string `yaml:"tenant_header_key"`
Backend string `yaml:"backend"`
TenantHeaderKey string `yaml:"tenant_header_key"`
ServicesQueryDuration time.Duration `yaml:"services_query_duration"`
}

// BuildConfigMap creates the Tempo ConfigMap for a monolithic deployment.
Expand Down Expand Up @@ -127,7 +129,7 @@ func BuildConfigMap(opts Options) (*corev1.ConfigMap, map[string]string, error)
extraAnnotations["tempo.grafana.com/tempoConfig.hash"] = fmt.Sprintf("%x", h)

if tempo.Spec.JaegerUI != nil && tempo.Spec.JaegerUI.Enabled {
tempoQueryConfig, err := buildTempoQueryConfig()
tempoQueryConfig, err := buildTempoQueryConfig(tempo.Spec.JaegerUI)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -268,10 +270,10 @@ func buildTempoConfig(opts Options) ([]byte, error) {
}
}

func buildTempoQueryConfig() ([]byte, error) {
func buildTempoQueryConfig(jaegerUISpec *v1alpha1.MonolithicJaegerUISpec) ([]byte, error) {
config := tempoQueryConfig{}
config.Backend = fmt.Sprintf("127.0.0.1:%d", manifestutils.PortHTTPServer)
config.TenantHeaderKey = manifestutils.TenantHeader

config.ServicesQueryDuration = jaegerUISpec.ServicesQueryDuration.Duration
return yaml.Marshal(&config)
}
Loading

0 comments on commit fff4c20

Please sign in to comment.