Skip to content

Commit

Permalink
feat: add operator metrics (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas authored Jul 31, 2023
1 parent 8c9ea4e commit c55a13d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 27 deletions.
11 changes: 9 additions & 2 deletions components/operator/apis/stack/v1beta3/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ type Broker struct {
type MonitoringSpec struct {
// +optional
Traces *TracesSpec `json:"traces,omitempty"`
// +optional
Metrics *MetricsSpec `json:"metrics,omitempty"`
}

type TracesOtlpSpec struct {
type OtlpSpec struct {
// +optional
Endpoint string `json:"endpoint,omitempty"`
// +optional
Expand All @@ -95,7 +97,12 @@ type TracesOtlpSpec struct {

type TracesSpec struct {
// +optional
Otlp *TracesOtlpSpec `json:"otlp,omitempty"`
Otlp *OtlpSpec `json:"otlp,omitempty"`
}

type MetricsSpec struct {
// +optional
Otlp *OtlpSpec `json:"otlp,omitempty"`
}

type ConfigurationSpec struct {
Expand Down
57 changes: 41 additions & 16 deletions components/operator/apis/stack/v1beta3/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 @@ -4167,6 +4167,26 @@ spec:
type: boolean
monitoring:
properties:
metrics:
properties:
otlp:
properties:
endpoint:
type: string
insecure:
type: boolean
mode:
enum:
- grpc
- http
type: string
port:
format: int32
type: integer
resourceAttributes:
type: string
type: object
type: object
traces:
properties:
otlp:
Expand Down
35 changes: 26 additions & 9 deletions components/operator/internal/modules/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,46 @@ import (
"github.com/formancehq/operator/internal/controllerutils"
)

type monitoringType string

const (
monitoringTypeTraces monitoringType = "TRACES"
monitoringTypeMetrics monitoringType = "METRICS"
)

func MonitoringEnvVarsWithPrefix(m stackv1beta3.MonitoringSpec, prefix string) ContainerEnv {
if m.Traces != nil {
return monitoringTracesEnvVars(m.Traces, prefix)
}
if m.Metrics != nil {
return monitoringMetricsEnvVars(m.Metrics, prefix)
}
return ContainerEnv{}
}

func monitoringTracesEnvVars(traces *stackv1beta3.TracesSpec, prefix string) ContainerEnv {
if traces.Otlp != nil {
return monitoringTracesOTLPEnvVars(traces.Otlp, prefix)
return monitoringOTLPEnvVars(traces.Otlp, prefix, monitoringTypeTraces)
}
return ContainerEnv{}
}

func monitoringMetricsEnvVars(metrics *stackv1beta3.MetricsSpec, prefix string) ContainerEnv {
if metrics.Otlp != nil {
return monitoringOTLPEnvVars(metrics.Otlp, prefix, monitoringTypeMetrics)
}
return ContainerEnv{}
}

func monitoringTracesOTLPEnvVars(otlp *stackv1beta3.TracesOtlpSpec, prefix string) ContainerEnv {
func monitoringOTLPEnvVars(otlp *stackv1beta3.OtlpSpec, prefix string, monitoringType monitoringType) ContainerEnv {
return ContainerEnv{
Env(fmt.Sprintf("%sOTEL_TRACES", prefix), "true"),
Env(fmt.Sprintf("%sOTEL_TRACES_EXPORTER", prefix), "otlp"),
EnvFromBool(fmt.Sprintf("%sOTEL_TRACES_EXPORTER_OTLP_INSECURE", prefix), otlp.Insecure),
Env(fmt.Sprintf("%sOTEL_TRACES_EXPORTER_OTLP_MODE", prefix), otlp.Mode),
Env(fmt.Sprintf("%sOTEL_TRACES_PORT", prefix), fmt.Sprint(otlp.Port)),
Env(fmt.Sprintf("%sOTEL_TRACES_ENDPOINT", prefix), otlp.Endpoint),
Env(fmt.Sprintf("%sOTEL_TRACES_EXPORTER_OTLP_ENDPOINT", prefix), controllerutils.ComputeEnvVar(prefix, "%s:%s", "OTEL_TRACES_ENDPOINT", "OTEL_TRACES_PORT")),
Env(fmt.Sprintf("%sOTEL_%s", prefix, string(monitoringType)), "true"),
Env(fmt.Sprintf("%sOTEL_%s_EXPORTER", prefix, string(monitoringType)), "otlp"),
EnvFromBool(fmt.Sprintf("%sOTEL_%s_EXPORTER_OTLP_INSECURE", prefix, string(monitoringType)), otlp.Insecure),
Env(fmt.Sprintf("%sOTEL_%s_EXPORTER_OTLP_MODE", prefix, string(monitoringType)), otlp.Mode),
Env(fmt.Sprintf("%sOTEL_%s_PORT", prefix, string(monitoringType)), fmt.Sprint(otlp.Port)),
Env(fmt.Sprintf("%sOTEL_%s_ENDPOINT", prefix, string(monitoringType)), otlp.Endpoint),
Env(fmt.Sprintf("%sOTEL_%s_EXPORTER_OTLP_ENDPOINT", prefix, string(monitoringType)), controllerutils.ComputeEnvVar(prefix, "%s:%s", fmt.Sprintf("OTEL_%s_ENDPOINT", string(monitoringType)), fmt.Sprintf("OTEL_%s_PORT", string(monitoringType)))),
Env(fmt.Sprintf("%sOTEL_RESOURCE_ATTRIBUTES", prefix), otlp.ResourceAttributes),
}
}

1 comment on commit c55a13d

@vercel
Copy link

@vercel vercel bot commented on c55a13d Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.