Skip to content

Commit 0a10f2f

Browse files
committed
feat: Add experimental feature to display Logs and Kubernetes events from Loki
1 parent bbb4122 commit 0a10f2f

15 files changed

+1668
-1137
lines changed

README.md

+134-36
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Grafana Scenes Kubernetes Application is a Grafana plugin that provides a way to
99

1010
This plugin relies on presence of default kube-state-metrics and node-exporter metrics.
1111

12-
### Current limitations
12+
### Requirements
1313

1414
* It expects the presence of `cluster` label on all the metrics.
15-
15+
1616
### Metrics used
1717

1818
Metrics and required labels used by application can be found in [metrics.ts](src/metrics/metrics.ts).
@@ -31,40 +31,6 @@ Metrics and required labels used by application can be found in [metrics.ts](src
3131
#### Daemonset
3232
<img src="screenshots/daemonset-view.png" style="width:25%;margin: 4px;"><img src="screenshots/daemonset-view-bottom.png" style="width:25%;margin: 4px;">
3333

34-
## Planned Features & Improvements
35-
36-
Following list is not in any particular order.
37-
38-
* Create page to view Node details.
39-
* Basic node details page is implemented.
40-
* Create page to view Deployment, StatefulSet, DaemonSet, CronJob and Job details.
41-
* Basic detailed pages for different resources is implemented.
42-
* Create page for Cluster overview.
43-
* Basic cluster overview page is implemented.
44-
* Implement sorting by columns.
45-
* Initial sorting for Pods is implemented.
46-
* Display alerts on the resources.
47-
* Alerts are displayed for Pods, DaemonSets and StatefulSets
48-
For alerts to be displayed alert needs to have `cluster` and kind label `pod|daemonset|statefulset` with name as the value.
49-
* Integrate OpenCost metrics to visualize cost of the resources.
50-
* Feature to show stopped resources.
51-
Because a lot of the queries are `instant` then the stopped resources are not shown even if time range is set to show them.
52-
* Partially implemented for pods, its possible to toggle to view which are not running anymore. It lookup pods using `present_over_time` with timerange
53-
specified in the UI time picker.
54-
* Add support for Karpenter metrics.
55-
Optional displaying of Karpenter metrics.
56-
Which could be toggled from the plugin settings.
57-
* Add support for resource relations.
58-
Depends on Kube-State-Metrics to expose relations between resources [Related feature request](https://github.com/kubernetes/kube-state-metrics/issues/2424).
59-
* Add support to see Kubernetes event logs
60-
Display events which have been exported by [kubernetes-event-exporter](https://github.com/resmoio/kubernetes-event-exporter) into Loki.
61-
* Display networking resources and metrics
62-
* Display Ingress metrics
63-
* Display Nginx Ingress Controller metrics (need to figure out how to make the connection between `kube_ingress_info` and if its nginx controlled)
64-
65-
66-
If you have any feature requests, improvements or suggestions, please create an issue.
67-
6834
## Installation
6935

7036
### Grafana deployed with Helm
@@ -94,6 +60,138 @@ grafana.ini:
9460
# Move the plugin from More Apps to Infrastructure in the menu
9561
k8s-app: infrastructure
9662
```
63+
64+
### Configuration
65+
66+
Application can be configured from the plugin settings page in Grafana.
67+
Settings page can be found at: `/plugins/k8s-app?page=configuration`.
68+
69+
#### Metrics settings
70+
71+
* Metrics datasource - Allows configuring regex to filter metrics from the prometheus datasources. (default=prometheus)
72+
* Default datasource - Allows configuring default datasource for the metrics.
73+
* Default cluster - Allows configuring default cluster to be used in the queries.
74+
* Cluster filter - Allows customizing the query which is used to get label values for the cluster variable.
75+
76+
#### Logs & Events settings (EXPERIMENTAL)
77+
78+
Allows displaying logs and events from Loki.
79+
80+
* Feature exepects events to be exported by [opentelemetry-collector-contrib k8seventsreceiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/k8seventsreceiver/README.md).
81+
* Logs must be exported to Loki by `opentelemetry-collector` because it relies on stream labels in format of `k8s_...`.
82+
* Datasource used must support multi-tenant queries where stream label `k8s_cluster_name` is used to select logs from specific tenant.
83+
* It is possible to override the default queries per view (Cluster, Node, Pod, Deployment, Statefulset, Daemonset).
84+
85+
##### Sample configuration for k8seventsreceiver
86+
87+
[Opentelemetry-collector helm chart](https://github.com/open-telemetry/opentelemetry-helm-charts/tree/main/charts/opentelemetry-collector) is used as a parent chart for the following configuration.
88+
89+
```yaml
90+
global:
91+
clusterName: "dummy-cluster"
92+
lokiEndpoint: "https://loki.example/otlp"
93+
94+
opentelemetry-collector:
95+
96+
mode: deployment
97+
98+
image:
99+
repository: "otel/opentelemetry-collector-contrib"
100+
101+
serviceAccount:
102+
create: true
103+
104+
clusterRole:
105+
create: true
106+
rules:
107+
# Allow the collector to read all resources in the cluster
108+
- apiGroups:
109+
- "*"
110+
resources:
111+
- "*"
112+
verbs: ["get", "watch", "list"]
113+
114+
ports:
115+
metrics:
116+
enabled: true
117+
otlp:
118+
enabled: false
119+
otlp-http:
120+
enabled: false
121+
jaeger-compact:
122+
enabled: false
123+
jaeger-thrift:
124+
enabled: false
125+
jaeger-grpc:
126+
enabled: false
127+
zipkin:
128+
enabled: false
129+
130+
resources:
131+
requests:
132+
memory: 128Mi
133+
cpu: 300m
134+
limits:
135+
memory: 512Mi
136+
cpu: 1000m
137+
138+
config:
139+
receivers:
140+
k8s_events:
141+
auth_type: "serviceAccount"
142+
exporters:
143+
otlphttp/loki:
144+
endpoint: "{{ .Values.global.lokiEndpoint }}"
145+
headers:
146+
"X-Scope-OrgID": "{{ .Values.global.clusterName }}"
147+
processors:
148+
resource:
149+
attributes:
150+
- key: k8s.cluster.name
151+
value: "{{ .Values.global.clusterName }}"
152+
action: insert
153+
- key: service.name
154+
value: "k8sevents"
155+
action: insert
156+
transform:
157+
error_mode: ignore
158+
log_statements:
159+
- context: log
160+
statements:
161+
# Move the namespace name to the resource attributes and remove it from the log attributes
162+
# This way Loki can use the namespace name as a stream label
163+
- set(resource.attributes["k8s.namespace.name"], attributes["k8s.namespace.name"]) where attributes["k8s.namespace.name"] != nil
164+
- delete_key(attributes, "k8s.namespace.name") where attributes["k8s.namespace.name"] != nil
165+
166+
service:
167+
extensions:
168+
- health_check
169+
pipelines:
170+
logs:
171+
exporters:
172+
- otlphttp/loki
173+
processors:
174+
- memory_limiter
175+
- resource
176+
- transform
177+
- batch
178+
receivers:
179+
- k8s_events
180+
metrics: null
181+
traces: null
182+
```
183+
184+
#### Ruler settings (EXPERIMENTAL)
185+
186+
Allows displaying additional information about the alerts which is not available in `ALERTS` and `ALERTS_FOR_STATE` metrics via labels.
187+
188+
* Currently rulers which support Prometheus HTTP REST API (Thanos, Mimir, Prometheus).
189+
* This feature displays `annotations` and `query` for each alert.
190+
191+
#### Analytics settings (EXPERIMENTAL)
192+
193+
Allows exporting of user views/visits of the application to Grafana analytics service.
194+
97195
## Contributing
98196

99197
### Local Development

0 commit comments

Comments
 (0)