Skip to content

Commit

Permalink
[FEAT] Add Grafana feature gate (#619)
Browse files Browse the repository at this point in the history
* [FEAT] Initial commit

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Create datasource definition

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Create datasource definition

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Update packages

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Creation of datasource

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Creation of datasource

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Creation of datasource

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Rename Datasources to grafana

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Rename Datasources to grafana

Signed-off-by: rita.canavarro <[email protected]>

* [FIX] Remove DatasourcesFeatureGates

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Move prune logit to tempo stack

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Started to move build Datasources

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Clean ups

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Clean up part 2

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Update Build args

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Dynamic URL

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Unit test

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Improve nil verify in test

Signed-off-by: rita.canavarro <[email protected]>

* [FEAT] Changelog

Signed-off-by: rita.canavarro <[email protected]>

* [REVERT] Go mod/sum

* [FEAT] Add missing pkg

Signed-off-by: rita.canavarro <[email protected]>

* [FIX] Go mods

Signed-off-by: rita.canavarro <[email protected]>

* [FIX] Unit test

Signed-off-by: rita.canavarro <[email protected]>

* add RBAC rules and mutate fn, update bundles and apidocs, add grafana.instanceSelector to select Grafana instance

Signed-off-by: Andreas Gerstmayr <[email protected]>

---------

Signed-off-by: rita.canavarro <[email protected]>
Signed-off-by: Andreas Gerstmayr <[email protected]>
Co-authored-by: Andreas Gerstmayr <[email protected]>
  • Loading branch information
ritaCanavarro and andreasgerstmayr authored Dec 7, 2023
1 parent bb9d581 commit e4444fe
Show file tree
Hide file tree
Showing 28 changed files with 593 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .chloggen/grafana_datasource.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: Create Grafana Tempo Operator datasource

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

# (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:
4 changes: 4 additions & 0 deletions apis/config/v1alpha1/projectconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ type FeatureGates struct {

// Observability configures observability features of the operator.
Observability ObservabilityFeatureGates `json:"observability,omitempty"`

// GrafanaOperator defines whether the Grafana Operator CRD exists in the cluster.
// This CRD is part of grafana-operator.
GrafanaOperator bool `json:"grafanaOperator,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
24 changes: 24 additions & 0 deletions apis/tempo/v1alpha1/tempostack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ type ObservabilitySpec struct {
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Tracing Config"
Tracing TracingConfigSpec `json:"tracing,omitempty"`

// Grafana defines the Grafana configuration for operands.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Grafana Config"
Grafana GrafanaConfigSpec `json:"grafana,omitempty"`
}

// MetricsConfigSpec defines a metrics config.
Expand Down Expand Up @@ -170,6 +177,23 @@ type TracingConfigSpec struct {
JaegerAgentEndpoint string `json:"jaeger_agent_endpoint,omitempty"`
}

// GrafanaConfigSpec defines configuration for Grafana.
type GrafanaConfigSpec struct {
// CreateDatasource specifies if a Grafana Datasource should be created for Tempo.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Create Datasource for Tempo"
CreateDatasource bool `json:"createDatasource,omitempty"`

// InstanceSelector specifies the Grafana instance where the datasource should be created.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Create CreateDatasource for Tempo"
InstanceSelector metav1.LabelSelector `json:"instanceSelector,omitempty"`
}

// PodStatusMap defines the type for mapping pod status to pod name.
type PodStatusMap map[corev1.PodPhase][]string

Expand Down
8 changes: 8 additions & 0 deletions apis/tempo/v1alpha1/tempostack_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func (v *validator) validateGateway(tempo TempoStack) field.ErrorList {
func (v *validator) validateObservability(tempo TempoStack) field.ErrorList {
observabilityBase := field.NewPath("spec").Child("observability")
metricsBase := observabilityBase.Child("metrics")
grafanaBase := observabilityBase.Child("grafana")

if tempo.Spec.Observability.Metrics.CreateServiceMonitors && !v.ctrlConfig.Gates.PrometheusOperator {
return field.ErrorList{
Expand Down Expand Up @@ -333,6 +334,13 @@ func (v *validator) validateObservability(tempo TempoStack) field.ErrorList {
}
}

if tempo.Spec.Observability.Grafana.CreateDatasource && !v.ctrlConfig.Gates.GrafanaOperator {
return field.ErrorList{
field.Invalid(grafanaBase.Child("createDatasource"), tempo.Spec.Observability.Grafana.CreateDatasource,
"the grafanaOperator feature gate must be enabled to create a Datasource for Tempo",
)}
}

return nil
}

Expand Down
19 changes: 18 additions & 1 deletion 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 @@ -28,6 +28,7 @@ data:
openshiftRoute: false
servingCertsService: false
prometheusOperator: false
grafanaOperator: false
httpEncryption: true
grpcEncryption: true
tlsProfile: Modern
Expand All @@ -45,6 +46,8 @@ data:
metrics:
createServiceMonitors: false
createPrometheusRules: false
grafana:
createDatasource: false
kind: ConfigMap
metadata:
labels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ metadata:
capabilities: Deep Insights
categories: Logging & Tracing,Monitoring
containerImage: ghcr.io/grafana/tempo-operator/tempo-operator
createdAt: "2023-11-20T13:45:36Z"
createdAt: "2023-12-07T18:57:13Z"
description: Create and manage deployments of Tempo, a high-scale distributed
tracing backend.
operatorframework.io/cluster-monitoring: "true"
Expand Down Expand Up @@ -201,6 +201,17 @@ spec:
- description: ObservabilitySpec defines how telemetry data gets handled.
displayName: Observability
path: observability
- description: Grafana defines the Grafana configuration for operands.
displayName: Grafana Config
path: observability.grafana
- description: CreateDatasource specifies if a Grafana Datasource should be
created for Tempo.
displayName: Create Datasource for Tempo
path: observability.grafana.createDatasource
- description: InstanceSelector specifies the Grafana instance where the datasource
should be created.
displayName: Create CreateDatasource for Tempo
path: observability.grafana.instanceSelector
- description: Metrics defines the metrics configuration for operands.
displayName: Metrics Config
path: observability.metrics
Expand Down Expand Up @@ -644,6 +655,18 @@ spec:
- get
- list
- watch
- apiGroups:
- grafana.integreatly.org
resources:
- grafanadatasources
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- monitoring.coreos.com
resources:
Expand Down
55 changes: 55 additions & 0 deletions bundle/community/manifests/tempo.grafana.com_tempostacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,61 @@ spec:
observability:
description: ObservabilitySpec defines how telemetry data gets handled.
properties:
grafana:
description: Grafana defines the Grafana configuration for operands.
properties:
createDatasource:
description: CreateDatasource specifies if a Grafana Datasource
should be created for Tempo.
type: boolean
instanceSelector:
description: InstanceSelector specifies the Grafana instance
where the datasource should be created.
properties:
matchExpressions:
description: matchExpressions is a list of label selector
requirements. The requirements are ANDed.
items:
description: A label selector requirement is a selector
that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector
applies to.
type: string
operator:
description: operator represents a key's relationship
to a set of values. Valid operators are In, NotIn,
Exists and DoesNotExist.
type: string
values:
description: values is an array of string values.
If the operator is In or NotIn, the values array
must be non-empty. If the operator is Exists or
DoesNotExist, the values array must be empty.
This array is replaced during a strategic merge
patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs.
A single {key,value} in the matchLabels map is equivalent
to an element of matchExpressions, whose key field is
"key", the operator is "In", and the values array contains
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
type: object
metrics:
description: Metrics defines the metrics configuration for operands.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data:
openshiftRoute: true
servingCertsService: true
prometheusOperator: true
grafanaOperator: false
httpEncryption: true
grpcEncryption: true
tlsProfile: Modern
Expand All @@ -45,6 +46,8 @@ data:
metrics:
createServiceMonitors: true
createPrometheusRules: true
grafana:
createDatasource: false
kind: ConfigMap
metadata:
labels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ metadata:
capabilities: Deep Insights
categories: Logging & Tracing,Monitoring
containerImage: ghcr.io/grafana/tempo-operator/tempo-operator
createdAt: "2023-11-20T13:45:34Z"
createdAt: "2023-12-07T18:32:18Z"
description: Create and manage deployments of Tempo, a high-scale distributed
tracing backend.
operatorframework.io/cluster-monitoring: "true"
Expand Down Expand Up @@ -201,6 +201,17 @@ spec:
- description: ObservabilitySpec defines how telemetry data gets handled.
displayName: Observability
path: observability
- description: Grafana defines the Grafana configuration for operands.
displayName: Grafana Config
path: observability.grafana
- description: CreateDatasource specifies if a Grafana Datasource should be
created for Tempo.
displayName: Create Datasource for Tempo
path: observability.grafana.createDatasource
- description: InstanceSelector specifies the Grafana instance where the datasource
should be created.
displayName: Create CreateDatasource for Tempo
path: observability.grafana.instanceSelector
- description: Metrics defines the metrics configuration for operands.
displayName: Metrics Config
path: observability.metrics
Expand Down Expand Up @@ -644,6 +655,18 @@ spec:
- get
- list
- watch
- apiGroups:
- grafana.integreatly.org
resources:
- grafanadatasources
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- monitoring.coreos.com
resources:
Expand Down
55 changes: 55 additions & 0 deletions bundle/openshift/manifests/tempo.grafana.com_tempostacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,61 @@ spec:
observability:
description: ObservabilitySpec defines how telemetry data gets handled.
properties:
grafana:
description: Grafana defines the Grafana configuration for operands.
properties:
createDatasource:
description: CreateDatasource specifies if a Grafana Datasource
should be created for Tempo.
type: boolean
instanceSelector:
description: InstanceSelector specifies the Grafana instance
where the datasource should be created.
properties:
matchExpressions:
description: matchExpressions is a list of label selector
requirements. The requirements are ANDed.
items:
description: A label selector requirement is a selector
that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector
applies to.
type: string
operator:
description: operator represents a key's relationship
to a set of values. Valid operators are In, NotIn,
Exists and DoesNotExist.
type: string
values:
description: values is an array of string values.
If the operator is In or NotIn, the values array
must be non-empty. If the operator is Exists or
DoesNotExist, the values array must be empty.
This array is replaced during a strategic merge
patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs.
A single {key,value} in the matchLabels map is equivalent
to an element of matchExpressions, whose key field is
"key", the operator is "In", and the values array contains
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
type: object
metrics:
description: Metrics defines the metrics configuration for operands.
properties:
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

grafanav1 "github.com/grafana-operator/grafana-operator/v5/api/v1beta1"
configv1 "github.com/openshift/api/config/v1"
openshiftoperatorv1 "github.com/openshift/api/operator/v1"
routev1 "github.com/openshift/api/route/v1"
Expand Down Expand Up @@ -41,6 +42,7 @@ func init() {
utilruntime.Must(openshiftoperatorv1.Install(scheme))
utilruntime.Must(configv1.Install(scheme))
utilruntime.Must(monitoringv1.AddToScheme(scheme))
utilruntime.Must(grafanav1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down
Loading

0 comments on commit e4444fe

Please sign in to comment.