Skip to content

Commit d3f105b

Browse files
authored
Create OpenShift dashboard to visualize Collector metrics (#2996)
* Create OpenShift dashboard to visualize Collector metrics #2995 Signed-off-by: Israel Blancas <[email protected]> * Add documentation Signed-off-by: Israel Blancas <[email protected]> * Typo Signed-off-by: Israel Blancas <[email protected]> * Change the dashboard to be a runnable Signed-off-by: Israel Blancas <[email protected]> * Apply changes requested in code review Signed-off-by: Israel Blancas <[email protected]> * Change flag Signed-off-by: Israel Blancas <[email protected]> --------- Signed-off-by: Israel Blancas <[email protected]>
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+
}

0 commit comments

Comments
 (0)