Skip to content

Commit d3f105b

Browse files
authoredJul 18, 2024
Create OpenShift dashboard to visualize Collector metrics (open-telemetry#2996)
* Create OpenShift dashboard to visualize Collector metrics open-telemetry#2995 Signed-off-by: Israel Blancas <iblancasa@gmail.com> * Add documentation Signed-off-by: Israel Blancas <iblancasa@gmail.com> * Typo Signed-off-by: Israel Blancas <iblancasa@gmail.com> * Change the dashboard to be a runnable Signed-off-by: Israel Blancas <iblancasa@gmail.com> * Apply changes requested in code review Signed-off-by: Israel Blancas <iblancasa@gmail.com> * Change flag Signed-off-by: Israel Blancas <iblancasa@gmail.com> --------- Signed-off-by: Israel Blancas <iblancasa@gmail.com>
1 parent d081fe5 commit d3f105b

File tree

4 files changed

+1173
-1
lines changed

4 files changed

+1173
-1
lines changed
 
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Create automatically an OpenShift dashboard to visualize OpenTelemetry Collector metrics
9+
10+
# One or more tracking issues related to the change
11+
issues: [2995]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: To enable this feature, you need to specify the `--openshift-create-dashboard` argument to the operator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package openshift
16+
17+
import (
18+
"context"
19+
_ "embed"
20+
21+
corev1 "k8s.io/api/core/v1"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/client-go/kubernetes"
25+
)
26+
27+
// The dashboard is created manually following the syntax from Grafana 5. For development purposes, this dashboard can be created just by loading the JSON file
28+
// in a ConfigMap from the openshift-config-managed and adding the console.openshift.io/dashboard=true label.
29+
//
30+
//go:embed metrics-dashboard.json
31+
var dashboardContent string
32+
33+
const (
34+
openshiftDashboardsNamespace = "openshift-config-managed"
35+
configMapName = "opentelemetry-collector"
36+
)
37+
38+
type DashboardManagement struct {
39+
clientset kubernetes.Interface
40+
}
41+
42+
func NewDashboardManagement(clientset kubernetes.Interface) DashboardManagement {
43+
return DashboardManagement{
44+
clientset: clientset,
45+
}
46+
}
47+
48+
func (d DashboardManagement) Start(ctx context.Context) error {
49+
cm := corev1.ConfigMap{
50+
ObjectMeta: v1.ObjectMeta{
51+
Name: configMapName,
52+
Namespace: openshiftDashboardsNamespace,
53+
Labels: map[string]string{
54+
"console.openshift.io/dashboard": "true",
55+
},
56+
},
57+
Data: map[string]string{
58+
"otel.json": dashboardContent,
59+
},
60+
}
61+
62+
_, err := d.clientset.CoreV1().ConfigMaps(openshiftDashboardsNamespace).Create(ctx, &cm, metav1.CreateOptions{})
63+
if err != nil {
64+
return nil
65+
}
66+
67+
<-ctx.Done()
68+
69+
return d.clientset.CoreV1().ConfigMaps(openshiftDashboardsNamespace).Delete(ctx, configMapName, metav1.DeleteOptions{})
70+
}
71+
72+
func (d DashboardManagement) NeedLeaderElection() bool {
73+
return true
74+
}

‎internal/openshift/dashboards/metrics-dashboard.json

+1,070
Large diffs are not rendered by default.

‎main.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import (
5454
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
5555
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
5656
"github.com/open-telemetry/opentelemetry-operator/internal/config"
57+
openshiftDashboards "github.com/open-telemetry/opentelemetry-operator/internal/openshift/dashboards"
5758
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
5859
"github.com/open-telemetry/opentelemetry-operator/internal/version"
5960
"github.com/open-telemetry/opentelemetry-operator/internal/webhook/podmutation"
@@ -111,6 +112,7 @@ func main() {
111112
pprofAddr string
112113
enableLeaderElection bool
113114
createRBACPermissions bool
115+
createOpenShiftDashboard bool
114116
enableMultiInstrumentation bool
115117
enableApacheHttpdInstrumentation bool
116118
enableDotNetInstrumentation bool
@@ -147,6 +149,7 @@ func main() {
147149
"Enable leader election for controller manager. "+
148150
"Enabling this will ensure there is only one active controller manager.")
149151
pflag.BoolVar(&createRBACPermissions, "create-rbac-permissions", false, "Automatically create RBAC permissions needed by the processors (deprecated)")
152+
pflag.BoolVar(&createOpenShiftDashboard, "openshift-create-dashboard", false, "Create an OpenShift dashboard for monitoring the OpenTelemetryCollector instances")
150153
pflag.BoolVar(&enableMultiInstrumentation, "enable-multi-instrumentation", false, "Controls whether the operator supports multi instrumentation")
151154
pflag.BoolVar(&enableApacheHttpdInstrumentation, constants.FlagApacheHttpd, true, "Controls whether the operator supports Apache HTTPD auto-instrumentation")
152155
pflag.BoolVar(&enableDotNetInstrumentation, constants.FlagDotNet, true, "Controls whether the operator supports dotnet auto-instrumentation")
@@ -215,6 +218,7 @@ func main() {
215218
"enable-nginx-instrumentation", enableNginxInstrumentation,
216219
"enable-nodejs-instrumentation", enableNodeJSInstrumentation,
217220
"enable-java-instrumentation", enableJavaInstrumentation,
221+
"create-openshift-dashboard", createOpenShiftDashboard,
218222
"zap-message-key", encodeMessageKey,
219223
"zap-level-key", encodeLevelKey,
220224
"zap-time-key", encodeTimeKey,
@@ -277,9 +281,17 @@ func main() {
277281
setupLog.Error(clientErr, "failed to create kubernetes clientset")
278282
}
279283

280-
reviewer := rbac.NewReviewer(clientset)
281284
ctx := ctrl.SetupSignalHandler()
282285

286+
if createOpenShiftDashboard {
287+
dashErr := mgr.Add(openshiftDashboards.NewDashboardManagement(clientset))
288+
if dashErr != nil {
289+
setupLog.Error(dashErr, "failed to create the OpenShift dashboards")
290+
}
291+
}
292+
293+
reviewer := rbac.NewReviewer(clientset)
294+
283295
// builds the operator's configuration
284296
ad, err := autodetect.New(restConfig, reviewer)
285297
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.