Skip to content

Commit d5c8942

Browse files
doc fix: streams docs and custom charts docs (#261)
1 parent e08d9ba commit d5c8942

File tree

3 files changed

+38
-45
lines changed

3 files changed

+38
-45
lines changed

docs/user-guide/dashboards/custom-charts/custom-charts-for-metrics-using-promql.md

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
21
This guide explains how to build custom charts for metrics in OpenObserve using PromQL. The goal is to help new and advanced users understand how raw metrics data transforms into a fully rendered chart through predictable and repeatable steps.
32

43
## How metric data flows into a chart
5-
Metrics data in OpenObserve follows a fixed transformation pipeline:
4+
Metrics data in OpenObserve follows a fixed transformation flow:
65

76
`Metrics data in OpenObserve > PromQL query > Matrix JSON > Transform into timestamp-value pairs > Render chart`
87

9-
This data pipeline never changes. Only two things vary:
8+
This data flow never changes. Only two things vary:
109

1110
- The **PromQL query**
1211
- The **JavaScript transformation logic** that prepares data based on the chart you want to build
1312

14-
The example uses the `container_cpu_time metric` and builds a time-series line chart.
15-
13+
The example uses the `container_cpu_time` metric and builds a time-series line chart.
1614

1715
## How to build the custom chart for metrics using PromQL
1816

@@ -121,15 +119,11 @@ The example uses the `container_cpu_time metric` and builds a time-series line c
121119
metric: { ...labels... },
122120
values: [
123121
[timestamp, value],
124-
125-
...
122+
...
126123
]
127-
}
128-
124+
}
129125
]
130-
131126
}
132-
133127
]
134128
```
135129
Here,
@@ -148,7 +142,7 @@ The example uses the `container_cpu_time metric` and builds a time-series line c
148142
??? "Step 5: Understand how to transform the data and render the chart"
149143
### Step 5: Understand how to transform the data and render the chart
150144
Now that you have inspected the raw PromQL response, you can prepare the data and build a chart.
151-
Every PromQL-based custom chart in OpenObserve follows the same pipeline:
145+
Every PromQL-based custom chart in OpenObserve follows the same flow:
152146
`data > transform > series > option > chart`
153147
The following subsections explain each part in the correct order.
154148

@@ -179,7 +173,7 @@ The example uses the `container_cpu_time metric` and builds a time-series line c
179173
Here:
180174

181175
- Each object inside result represents one metric series.
182-
- The metric object holds all identifying labels.
176+
- The `metric` object holds all identifying labels.
183177
- The values array holds the actual time-series data as `[timestamp, value]`.
184178

185179

@@ -255,52 +249,51 @@ The example uses the `container_cpu_time metric` and builds a time-series line c
255249
**JavaScript code:**
256250

257251
```js linenums="1"
252+
/// Set the chart type you want
253+
// Supported examples: "line", "scatter", "bar"
254+
const chartType = "bar";
255+
258256
// Step 1: prepare an empty list of series
259257
const series = [];
260258

261259
// Step 2: read the PromQL response from OpenObserve
262260
if (Array.isArray(data) && data.length > 0) {
263261
const query = data[0];
264-
if (query.result && Array.isArray(query.result)) {
265-
for (const item of query.result) {
266-
if (!Array.isArray(item.values)) {
267-
continue;
268-
}
269262

270-
// Step 3: convert [timestamp, value] to [ISO time, number]
271-
const points = item.values.map(([timestamp, value]) => [
272-
new Date(timestamp * 1000).toISOString(),
273-
Number(value)
274-
]);
263+
if (query.result && Array.isArray(query.result)) {
264+
for (const item of query.result) {
265+
if (!Array.isArray(item.values)) {
266+
continue;
267+
}
275268

276-
// Step 4: choose a label for the legend
277-
const name =
278-
item.metric.k8s_pod_name ||
279-
item.metric.container_id ||
280-
"unknown";
281-
282-
// Step 5: add one line series for this metric
283-
series.push({
284-
name: name,
285-
type: "line",
286-
data: points,
287-
smooth: true,
288-
showSymbol: false
289-
});
269+
// Step 3: convert [timestamp, value] to [ISO time, number]
270+
const points = item.values.map(([timestamp, value]) => [
271+
new Date(timestamp * 1000).toISOString(),
272+
Number(value)
273+
]);
290274

291-
}
275+
// Step 4: choose a label for the legend
276+
const name =
277+
item.metric.k8s_pod_name ||
278+
item.metric.container_id ||
279+
"unknown";
292280

281+
// Step 5: add one series entry for this metric
282+
series.push({
283+
name: name,
284+
type: ,
285+
data: points
286+
});
287+
}
293288
}
294-
295289
}
296290

297291
// Step 6: define how the chart should be drawn
298-
299292
option = {
300-
tooltip: { trigger: "axis" },
301-
legend: { type: "scroll", top: "top" },
302293
xAxis: { type: "time", name: "Time" },
303294
yAxis: { type: "value", name: "Value" },
295+
legend: { type: "scroll", top: "top" },
296+
tooltip: { trigger: chartType === "scatter" ? "item" : "axis" },
304297
series: series
305298
};
306299
```

docs/user-guide/streams/.pages

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ nav:
55
- Schema Settings: schema-settings.md
66
- Extended Retention: extended-retention.md
77
- Summary Streams: summary-streams.md
8-
- Field and Index Types in Streams: fields-and-index-in-streams.md
8+
- Field and Index Types in Streams: data-type-and-index-type-in-streams.md
99
- Query Recommendations Stream: query-recommendations.md
1010
- Distinct Values: distinct-values.md
1111

docs/user-guide/streams/schema-settings.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ For example:
2222
- `58.0` as `Float64`
2323
- `"58%"` as `Utf8`
2424

25-
## Index Type
25+
## Index type
2626
You can modify or assign an index type to a field to improve search performance. Indexing can reduce the amount of data that must be scanned during queries.
2727

28-
To learn more, visit the [Fields and Index in Streams](streams/fields-and-index-in-streams) page.
28+
To learn more, visit the [Fields and Index in Streams](https://openobserve.ai/docs/user-guide/streams/data-type-and-index-type-in-streams/) page.
2929

3030
!!! Warning
3131
Changing the index after storing data may lead to inconsistent query results or data retrieval failures.

0 commit comments

Comments
 (0)