Skip to content

Commit

Permalink
feat: manage Perses dashboards via the operator
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Oct 2, 2024
1 parent 86b1104 commit 87acbd0
Show file tree
Hide file tree
Showing 47 changed files with 1,824 additions and 284 deletions.
16 changes: 16 additions & 0 deletions api/dash0monitoring/v1alpha1/operator_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ func (d *Dash0OperatorConfiguration) EnsureResourceIsMarkedAsDegraded(
})
}

func (d *Dash0OperatorConfiguration) GetDash0AuthorizationIfConfigured() *Authorization {
if d.Spec.Export == nil {
return nil
}
if d.Spec.Export.Dash0 == nil {
return nil
}

authorization := d.Spec.Export.Dash0.Authorization
if (authorization.Token != nil && *authorization.Token != "") ||
(authorization.SecretRef != nil && authorization.SecretRef.Name != "" && authorization.SecretRef.Key != "") {
return &authorization
}
return nil
}

func (d *Dash0OperatorConfiguration) GetResourceTypeName() string {
return "Dash0OperatorConfiguration"
}
Expand Down
9 changes: 9 additions & 0 deletions api/dash0monitoring/v1alpha1/types_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ type Dash0Configuration struct {
//
// +kubebuilder:validation:Required
Authorization Authorization `json:"authorization"`

// The base URL of the Dash0 API to talk to. This is not where telemetry will be sent, but it is used for managing
// dashboards and check rules via the operator. This property is mandatory. The value needs to be the API endpoint
// of your Dash0 organization. The correct API endpoint can be copied fom https://app.dash0.com -> organization
// settings -> "Endpoints" -> "API". The correct endpoint value will always start with "https://api." and end in
// ".dash0.com"
//
// +kubebuilder:validation:Optional
ApiEndpoint string `json:"apiEndpoint,omitempty"`
}

// Authorization contains the authorization settings for Dash0.
Expand Down
40 changes: 31 additions & 9 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/go-logr/logr"
persesv1alpha1 "github.com/perses/perses-operator/api/v1alpha1"
semconv "go.opentelemetry.io/collector/semconv/v1.27.0"
otelmetric "go.opentelemetry.io/otel/metric"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -60,6 +62,7 @@ type environmentVariables struct {
configurationReloaderImagePullPolicy corev1.PullPolicy
filelogOffsetSynchImage string
filelogOffsetSynchImagePullPolicy corev1.PullPolicy
selfMonitoringAndApiAuthToken string
}

const (
Expand Down Expand Up @@ -100,9 +103,11 @@ var (

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(dash0v1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme

// for perses dashboard controller, prometheus scrape config controller etc.
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
utilruntime.Must(persesv1alpha1.AddToScheme(scheme))
}

func main() {
Expand All @@ -111,6 +116,7 @@ func main() {
var operatorConfigurationToken string
var operatorConfigurationSecretRefName string
var operatorConfigurationSecretRefKey string
var operatorConfigurationApiEndpoint string
var isUninstrumentAll bool
var metricsAddr string
var enableLeaderElection bool
Expand All @@ -132,6 +138,8 @@ func main() {
flag.StringVar(&operatorConfigurationSecretRefKey, "operator-configuration-secret-ref-key", "",
"The key in an existing Kubernetes secret containing the Dash0 auth token, used to creating an operator "+
"configuration resource.")
flag.StringVar(&operatorConfigurationApiEndpoint, "operator-configuration-api-endpoint", "",
"The Dash0 API endpoint for managing dashboards and check rules via the operator.")
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
Expand Down Expand Up @@ -223,6 +231,9 @@ func main() {
Key: operatorConfigurationSecretRefKey,
},
}
if len(operatorConfigurationApiEndpoint) > 0 {
operatorConfiguration.ApiEndpoint = operatorConfigurationApiEndpoint
}
}

if err = startOperatorManager(
Expand Down Expand Up @@ -389,6 +400,8 @@ func readEnvironmentVariables() error {
filelogOffsetSynchImagePullPolicy :=
readOptionalPullPolicyFromEnvironmentVariable(filelogOffsetSynchImagePullPolicyEnvVarName)

selfMonitoringAndApiAuthToken := os.Getenv(util.SelfMonitoringAndApiAuthTokenEnvVarName)

envVars = environmentVariables{
operatorNamespace: operatorNamespace,
deploymentName: deploymentName,
Expand All @@ -402,6 +415,7 @@ func readEnvironmentVariables() error {
configurationReloaderImagePullPolicy: configurationReloaderImagePullPolicy,
filelogOffsetSynchImage: filelogOffsetSynchImage,
filelogOffsetSynchImagePullPolicy: filelogOffsetSynchImagePullPolicy,
selfMonitoringAndApiAuthToken: selfMonitoringAndApiAuthToken,
}

return nil
Expand Down Expand Up @@ -504,14 +518,22 @@ func startDash0Controllers(
return fmt.Errorf("unable to set up the backend connection reconciler: %w", err)
}

persesDashboardCrdReconciler := &controller.PersesDashboardCrdReconciler{
AuthToken: envVars.selfMonitoringAndApiAuthToken,
}
if err := persesDashboardCrdReconciler.SetupWithManager(ctx, mgr, startupTasksK8sClient, &setupLog); err != nil {
return fmt.Errorf("unable to set up the Perses dashboard reconciler: %w", err)
}

operatorConfigurationReconciler := &controller.OperatorConfigurationReconciler{
Client: k8sClient,
Clientset: clientset,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("dash0-operator-configuration-controller"),
DeploymentSelfReference: deploymentSelfReference,
Images: images,
DevelopmentMode: developmentMode,
Client: k8sClient,
Clientset: clientset,
PersesDashboardCrdReconciler: persesDashboardCrdReconciler,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("dash0-operator-configuration-controller"),
DeploymentSelfReference: deploymentSelfReference,
Images: images,
DevelopmentMode: developmentMode,
}
if err := operatorConfigurationReconciler.SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to set up the operator configuration reconciler: %w", err)
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/operator.dash0.com_dash0monitorings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ spec:
description: The configuration of the Dash0 ingress endpoint to
which telemetry data will be sent.
properties:
apiEndpoint:
description: |-
The base URL of the Dash0 API to talk to. This is not where telemetry will be sent, but it is used for managing
dashboards and check rules via the operator. This property is mandatory. The value needs to be the API endpoint
of your Dash0 organization. The correct API endpoint can be copied fom https://app.dash0.com -> organization
settings -> "Endpoints" -> "API". The correct endpoint value will always start with "https://api." and end in
".dash0.com"
type: string
authorization:
description: Mandatory authorization settings for sending
data to Dash0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ spec:
description: The configuration of the Dash0 ingress endpoint to
which telemetry data will be sent.
properties:
apiEndpoint:
description: |-
The base URL of the Dash0 API to talk to. This is not where telemetry will be sent, but it is used for managing
dashboards and check rules via the operator. This property is mandatory. The value needs to be the API endpoint
of your Dash0 organization. The correct API endpoint can be copied fom https://app.dash0.com -> organization
settings -> "Endpoints" -> "API". The correct endpoint value will always start with "https://api." and end in
".dash0.com"
type: string
authorization:
description: Mandatory authorization settings for sending
data to Dash0.
Expand Down
16 changes: 16 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ kind: ClusterRole
metadata:
name: manager-role
rules:
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- list
- watch
- apiGroups:
- apps
resources:
Expand Down Expand Up @@ -111,3 +119,11 @@ rules:
- get
- patch
- update
- apiGroups:
- perses.dev
resources:
- persesdashboards
verbs:
- get
- list
- watch
17 changes: 15 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ require (
github.com/google/uuid v1.6.0
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/perses/perses-operator v0.0.0-20240402153734-4ccf03f6c8e6
go.opentelemetry.io/collector/pdata v1.16.0
go.opentelemetry.io/collector/semconv v0.110.0
go.opentelemetry.io/otel/metric v1.30.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.31.1
k8s.io/apiextensions-apiserver v0.31.0
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/yaml v1.4.0
)

require (
emperror.dev/errors v0.8.1 // indirect
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -33,6 +37,7 @@ require (
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
Expand All @@ -49,18 +54,27 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/nexucis/lamenv v0.5.2 // indirect
github.com/perses/common v0.23.1 // indirect
github.com/perses/perses v0.44.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zitadel/oidc/v3 v3.18.0 // indirect
github.com/zitadel/schema v1.3.0 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.30.0 // indirect
Expand All @@ -70,6 +84,7 @@ require (
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
Expand All @@ -86,12 +101,10 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/dash0hq/dash0-operator/images/pkg/common => ./images/pkg/common
Loading

0 comments on commit 87acbd0

Please sign in to comment.