Skip to content

Commit

Permalink
feat: add otel collector uri flag (#513)
Browse files Browse the repository at this point in the history
Signed-off-by: Leopold Jacquot <leopold.jacquot@infomaniak.com>
  • Loading branch information
L3o-pold authored Aug 4, 2023
1 parent e740068 commit 31d8d5a
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 17 deletions.
8 changes: 8 additions & 0 deletions apis/core/v1alpha1/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ type FlagSourceConfigurationSpec struct {
// DebugLogging defines whether to enable --debug flag of flagd sidecar. Default false (disabled).
// +optional
DebugLogging *bool `json:"debugLogging"`

// OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled).
// +optional
OtelCollectorUri string `json:"otelCollectorUri"`
}

type Source struct {
Expand Down Expand Up @@ -204,6 +208,7 @@ func NewFlagSourceConfigurationSpec() (*FlagSourceConfigurationSpec, error) {
LogFormat: defaultLogFormat,
RolloutOnChange: nil,
DebugLogging: utils.FalseVal(),
OtelCollectorUri: "",
}

// set default value derived from constant default
Expand Down Expand Up @@ -318,6 +323,9 @@ func (fc *FlagSourceConfigurationSpec) Merge(new *FlagSourceConfigurationSpec) {
if new.DebugLogging != nil {
fc.DebugLogging = new.DebugLogging
}
if new.OtelCollectorUri != "" {
fc.OtelCollectorUri = new.OtelCollectorUri
}
}

func (fc *FlagSourceConfigurationSpec) ToEnvVars() []corev1.EnvVar {
Expand Down
5 changes: 5 additions & 0 deletions apis/core/v1alpha1/flagsourceconfiguration_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
RolloutOnChange: utils.TrueVal(),
ProbesEnabled: utils.TrueVal(),
DebugLogging: utils.TrueVal(),
OtelCollectorUri: "",
},
}

Expand Down Expand Up @@ -159,6 +160,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
RolloutOnChange: utils.TrueVal(),
ProbesEnabled: utils.TrueVal(),
DebugLogging: utils.TrueVal(),
OtelCollectorUri: "",
},
}, ff_old)

Expand Down Expand Up @@ -193,6 +195,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
RolloutOnChange: utils.FalseVal(),
ProbesEnabled: utils.FalseVal(),
DebugLogging: utils.FalseVal(),
OtelCollectorUri: "",
},
}

Expand Down Expand Up @@ -245,6 +248,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
RolloutOnChange: utils.FalseVal(),
ProbesEnabled: utils.FalseVal(),
DebugLogging: utils.FalseVal(),
OtelCollectorUri: "",
},
}, ff_old)
}
Expand Down Expand Up @@ -281,6 +285,7 @@ func Test_FLagSourceConfiguration_NewFlagSourceConfigurationSpec(t *testing.T) {
LogFormat: "val5",
ProbesEnabled: utils.TrueVal(),
DebugLogging: utils.FalseVal(),
OtelCollectorUri: "",
}, fs)

//error paths
Expand Down
1 change: 1 addition & 0 deletions apis/core/v1alpha2/flagsourceconfiguration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error {
DefaultSyncProvider: v1alpha1.SyncProviderType(src.Spec.DefaultSyncProvider),
ProbesEnabled: src.Spec.ProbesEnabled,
DebugLogging: utils.FalseVal(),
OtelCollectorUri: src.Spec.OtelCollectorUri,
}
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions apis/core/v1alpha2/flagsourceconfiguration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
RolloutOnChange: &tt,
SyncProviderArgs: []string{"provider", "arg"},
DebugLogging: utils.FalseVal(),
OtelCollectorUri: "",
},
},
wantErr: false,
Expand Down Expand Up @@ -155,6 +156,7 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
RolloutOnChange: nil,
SyncProviderArgs: []string{"provider", "arg"},
DebugLogging: utils.FalseVal(),
OtelCollectorUri: "",
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions apis/core/v1alpha2/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ type FlagSourceConfigurationSpec struct {
// ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true (enabled).
// +optional
ProbesEnabled *bool `json:"probesEnabled"`

// OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled).
// +optional
OtelCollectorUri string `json:"otelCollectorUri"`
}

// FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration
Expand Down
2 changes: 2 additions & 0 deletions apis/core/v1alpha3/flagsourceconfiguration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error {
RolloutOnChange: src.Spec.RolloutOnChange,
ProbesEnabled: src.Spec.ProbesEnabled,
DebugLogging: src.Spec.DebugLogging,
OtelCollectorUri: src.Spec.OtelCollectorUri,
}
return nil
}
Expand Down Expand Up @@ -106,6 +107,7 @@ func (dst *FlagSourceConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
RolloutOnChange: src.Spec.RolloutOnChange,
ProbesEnabled: src.Spec.ProbesEnabled,
DebugLogging: src.Spec.DebugLogging,
OtelCollectorUri: src.Spec.OtelCollectorUri,
}
return nil
}
2 changes: 2 additions & 0 deletions apis/core/v1alpha3/flagsourceconfiguration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
EnvVarPrefix: "pre",
RolloutOnChange: &tt,
DebugLogging: utils.FalseVal(),
OtelCollectorUri: "",
},
},
wantErr: false,
Expand Down Expand Up @@ -220,6 +221,7 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
EnvVarPrefix: "pre",
RolloutOnChange: &tt,
DebugLogging: utils.FalseVal(),
OtelCollectorUri: "",
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions apis/core/v1alpha3/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ type FlagSourceConfigurationSpec struct {
// DebugLogging defines whether to enable --debug flag of flagd sidecar. Default false (disabled).
// +optional
DebugLogging *bool `json:"debugLogging"`

// OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled).
// +optional
OtelCollectorUri string `json:"otelCollectorUri"`
}

type Source struct {
Expand Down
6 changes: 5 additions & 1 deletion chart/open-feature-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ helm uninstall open-feature-operator

The command removes all the Kubernetes components associated with the chart and deletes the release.

<!-- x-release-please-start-version -->
## Configuration

### Global
Expand All @@ -106,6 +107,7 @@ The command removes all the Kubernetes components associated with the chart and
| `sidecarConfiguration.logFormat` | Sets the value of the `XXX_LOG_FORMAT` environment variable for the injected sidecar container. There are 2 valid log formats: `json` and `console`. | `json` |
| `sidecarConfiguration.probesEnabled` | Enable or Disable Liveness and Readiness probes of the flagd sidecar. When enabled, HTTP probes( paths - `/readyz`, `/healthz`) are set with an initial delay of 5 seconds. | `true` |
| `sidecarConfiguration.debugLogging` | Controls the addition of the `--debug` flag to the container startup arguments. | `false` |
| `sidecarConfiguration.otelCollectorUri` | Otel exporter uri. | `""` |

### Flagd-proxy configuration

Expand All @@ -128,7 +130,7 @@ The command removes all the Kubernetes components associated with the chart and
| `controllerManager.kubeRbacProxy.resources.requests.cpu` | Sets cpu resource requests for kube-rbac-proxy. | `5m` |
| `controllerManager.kubeRbacProxy.resources.requests.memory` | Sets memory resource requests for kube-rbac-proxy. | `64Mi` |
| `controllerManager.manager.image.repository` | Sets the image for the operator. | `ghcr.io/open-feature/open-feature-operator` |
| `controllerManager.manager.image.tag` | Sets the version tag for the operator. | `v0.2.34` |
| `controllerManager.manager.image.tag` | Sets the version tag for the operator. | `v0.2.35` |
| `controllerManager.manager.resources.limits.cpu` | Sets cpu resource limits for operator. | `500m` |
| `controllerManager.manager.resources.limits.memory` | Sets memory resource limits for operator. | `128Mi` |
| `controllerManager.manager.resources.requests.cpu` | Sets cpu resource requests for operator. | `10m` |
Expand All @@ -137,3 +139,5 @@ The command removes all the Kubernetes components associated with the chart and
| `managerConfig.controllerManagerConfigYaml.health.healthProbeBindAddress` | Sets the bind address for health probes. | `:8081` |
| `managerConfig.controllerManagerConfigYaml.metrics.bindAddress` | Sets the bind address for metrics. | `127.0.0.1:8080` |
| `managerConfig.controllerManagerConfigYaml.webhook.port` | Sets the bind address for webhook. | `9443` |

<!-- x-release-please-end -->
2 changes: 2 additions & 0 deletions chart/open-feature-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ sidecarConfiguration:
probesEnabled: true
## @param sidecarConfiguration.debugLogging Controls the addition of the `--debug` flag to the container startup arguments.
debugLogging: false
## @param sidecarConfiguration.otelCollectorUri Otel exporter uri.
otelCollectorUri: ""

## @section Flagd-proxy configuration
flagdProxyConfiguration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ spec:
C_IDENTIFIER.
type: string
value:
description: 'Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core '
description: 'Variable references $(VAR_NAME) are expanded
using the previously defined environment variables in
the container and any service environment variables. If
a variable cannot be resolved, the reference in the input
string will be unchanged. Double $$ are reduced to a single
$, which allows for escaping the $(VAR_NAME) syntax: i.e.
"$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)".
Escaped references will never be expanded, regardless
of whether the variable exists or not. Defaults to "".'
type: string
valueFrom:
description: Source for the environment variable's value.
Expand Down Expand Up @@ -330,7 +338,15 @@ spec:
C_IDENTIFIER.
type: string
value:
description: 'Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core'
description: 'Variable references $(VAR_NAME) are expanded
using the previously defined environment variables in
the container and any service environment variables. If
a variable cannot be resolved, the reference in the input
string will be unchanged. Double $$ are reduced to a single
$, which allows for escaping the $(VAR_NAME) syntax: i.e.
"$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)".
Escaped references will never be expanded, regardless
of whether the variable exists or not. Defaults to "".'
type: string
valueFrom:
description: Source for the environment variable's value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ spec:
description: Name of the environment variable. Must be a C_IDENTIFIER.
type: string
value:
description: 'Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core'
description: 'Variable references $(VAR_NAME) are expanded using
the previously defined environment variables in the container
and any service environment variables. If a variable cannot
be resolved, the reference in the input string will be unchanged.
Double $$ are reduced to a single $, which allows for escaping
the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the
string literal "$(VAR_NAME)". Escaped references will never
be expanded, regardless of whether the variable exists or
not. Defaults to "".'
type: string
valueFrom:
description: Source for the environment variable's value. Cannot
Expand Down Expand Up @@ -169,6 +177,10 @@ spec:
to 8014
format: int32
type: integer
otelCollectorUri:
description: OtelCollectorUri defines whether to enable --otel-collector-uri
flag of flagd sidecar. Default false (disabled).
type: string
port:
description: Port defines the port to listen on, defaults to 8013
format: int32
Expand Down Expand Up @@ -284,6 +296,10 @@ spec:
to 8013
format: int32
type: integer
otelCollectorUri:
description: OtelCollectorUri defines whether to enable --otel-collector-uri
flag of flagd sidecar. Default false (disabled).
type: string
port:
description: Port defines the port to listen on, defaults to 8014
format: int32
Expand Down Expand Up @@ -360,7 +376,15 @@ spec:
description: Name of the environment variable. Must be a C_IDENTIFIER.
type: string
value:
description: 'Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core'
description: 'Variable references $(VAR_NAME) are expanded using
the previously defined environment variables in the container
and any service environment variables. If a variable cannot
be resolved, the reference in the input string will be unchanged.
Double $$ are reduced to a single $, which allows for escaping
the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the
string literal "$(VAR_NAME)". Escaped references will never
be expanded, regardless of whether the variable exists or
not. Defaults to "".'
type: string
valueFrom:
description: Source for the environment variable's value. Cannot
Expand Down Expand Up @@ -467,6 +491,10 @@ spec:
to 8014
format: int32
type: integer
otelCollectorUri:
description: OtelCollectorUri defines whether to enable --otel-collector-uri
flag of flagd sidecar. Default false (disabled).
type: string
port:
description: Port defines the port to listen on, defaults to 8013
format: int32
Expand Down
15 changes: 15 additions & 0 deletions controllers/common/flagd-injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ func (fi *FlagdContainerInjector) InjectFlagd(
)
}

// set --otel-collector-uri flag if enabled
if flagSourceConfig.OtelCollectorUri != "" {
flagdContainer.Args = append(
flagdContainer.Args,
"--metrics-exporter",
"otel",
)

flagdContainer.Args = append(
flagdContainer.Args,
"--otel-collector-uri",
flagSourceConfig.OtelCollectorUri,
)
}

addFlagdContainer(podSpec, flagdContainer)

return nil
Expand Down
39 changes: 39 additions & 0 deletions controllers/common/flagd-injector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,45 @@ func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithDebugLogging(t *te
require.Equal(t, expectedDeployment, deployment)
}

func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithOtelCollectorUri(t *testing.T) {

namespace, fakeClient := initContainerInjectionTestEnv()

fi := &FlagdContainerInjector{
Client: fakeClient,
Logger: testr.New(t),
FlagdProxyConfig: getProxyConfig(),
FlagDResourceRequirements: getResourceRequirements(),
}

deployment := appsV1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "my-deployment",
Namespace: namespace,
},
Spec: appsV1.DeploymentSpec{},
}

flagSourceConfig := getFlagSourceConfigSpec()

flagSourceConfig.DefaultSyncProvider = v1alpha1.SyncProviderGrpc

flagSourceConfig.OtelCollectorUri = "localhost:4317"

flagSourceConfig.Sources = []v1alpha1.Source{{}}

err := fi.InjectFlagd(context.Background(), &deployment.ObjectMeta, &deployment.Spec.Template.Spec, flagSourceConfig)
require.Nil(t, err)

expectedDeployment := getExpectedDeployment(namespace)

expectedDeployment.Annotations = nil

expectedDeployment.Spec.Template.Spec.Containers[0].Args = []string{"start", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]", "--metrics-exporter", "otel", "--otel-collector-uri", "localhost:4317"}

require.Equal(t, expectedDeployment, deployment)
}

func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithSyncProviderArgs(t *testing.T) {

namespace, fakeClient := initContainerInjectionTestEnv()
Expand Down
Loading

0 comments on commit 31d8d5a

Please sign in to comment.