|
1 | 1 | package org.ebean.monitor.api; |
2 | 2 |
|
3 | 3 | import io.avaje.jsonb.Json; |
| 4 | +import io.avaje.recordbuilder.RecordBuilder; |
4 | 5 |
|
5 | 6 | import java.util.ArrayList; |
6 | 7 | import java.util.LinkedHashMap; |
|
9 | 10 |
|
10 | 11 | /** |
11 | 12 | * Metrics to ingest. |
| 13 | + * |
| 14 | + * @param v Metric payload format version. {@code 0}/absent means legacy v1 (flat |
| 15 | + * names, no tags); {@code 2} means v2 (canonical family {@code name} + |
| 16 | + * delimited {@code tags} string on each {@link MetricData}). |
| 17 | + * @param startEventTime Optional start of the metric window provided by the client (epoch |
| 18 | + * millis, typically the {@code eventTime} of the prior successful send, |
| 19 | + * or the reporter start time on the first send). When non-zero, the OTLP |
| 20 | + * forwarder uses this as {@code startTimeUnixNano} so consecutive deltas |
| 21 | + * are truly disjoint and survive |
| 22 | + * {@code otelcol.processor.deltatocumulative}. |
| 23 | + * @param eventTime The metric collection time. |
| 24 | + * @param appName The name of the application the metrics are collected for. |
| 25 | + * @param version The application version. Used to determine when new versions are released. |
| 26 | + * @param environment The name of the environment the metrics are collected for. |
| 27 | + * @param instanceId An Id for the server instance (eg. Kubernetes pod name). |
| 28 | + * @param metrics General metrics for the application (Rest endpoints, JVM metrics, |
| 29 | + * CGroup metrics etc). |
| 30 | + * @param dbs The database metrics. |
| 31 | + * @param resAttrs Optional extra resource attributes — typically parsed from the standard |
| 32 | + * {@code OTEL_RESOURCE_ATTRIBUTES} env var by the client. Forwarded |
| 33 | + * verbatim to the OTLP {@code resource.attributes} list. The reserved |
| 34 | + * per-app fields ({@code service.name}, {@code service.version}, |
| 35 | + * {@code service.instance.id}, {@code deployment.environment.name}) |
| 36 | + * sourced from the dedicated header fields above take precedence over any |
| 37 | + * matching keys here. |
12 | 38 | */ |
| 39 | +@RecordBuilder |
13 | 40 | @Json |
14 | | -public class MetricRequest { |
| 41 | +public record MetricRequest( |
| 42 | + int v, |
| 43 | + long startEventTime, |
| 44 | + long eventTime, |
| 45 | + String appName, |
| 46 | + String version, |
| 47 | + String environment, |
| 48 | + String instanceId, |
| 49 | + List<MetricData> metrics, |
| 50 | + List<MetricDbData> dbs, |
| 51 | + Map<String, String> resAttrs |
| 52 | +) { |
15 | 53 |
|
16 | | - /** |
17 | | - * Metric payload format version. {@code 0}/absent means legacy v1 (flat names, |
18 | | - * no tags); {@code 2} means v2 (canonical family {@code name} + delimited |
19 | | - * {@code tags} string on each {@link MetricData}). Parsing only at this stage. |
20 | | - */ |
21 | | - public int v; |
22 | | - |
23 | | - /** |
24 | | - * Optional start of the metric window provided by the client (epoch millis, |
25 | | - * typically the {@code eventTime} of the prior successful send, or the |
26 | | - * reporter start time on the first send). When non-zero, the OTLP forwarder |
27 | | - * uses this as {@code startTimeUnixNano} so consecutive deltas are truly |
28 | | - * disjoint and survive {@code otelcol.processor.deltatocumulative}. |
29 | | - */ |
30 | | - public long startEventTime; |
31 | | - |
32 | | - /** |
33 | | - * The metric collection time. |
34 | | - */ |
35 | | - public long eventTime; |
36 | | - |
37 | | - /** |
38 | | - * The name of the application the metrics are collected for. |
39 | | - */ |
40 | | - public String appName; |
41 | | - |
42 | | - /** |
43 | | - * The application version. Used to determine when new versions are released. |
44 | | - */ |
45 | | - public String version; |
| 54 | + public MetricRequest { |
| 55 | + metrics = (metrics == null) ? new ArrayList<>() : metrics; |
| 56 | + dbs = (dbs == null) ? new ArrayList<>() : dbs; |
| 57 | + resAttrs = (resAttrs == null) ? new LinkedHashMap<>() : resAttrs; |
| 58 | + } |
46 | 59 |
|
47 | 60 | /** |
48 | | - * The name of the environment the metrics are collected for. |
| 61 | + * Create a new builder. |
49 | 62 | */ |
50 | | - public String environment; |
51 | | - |
52 | | - /** |
53 | | - * An Id for the server instance (eg. Kubernetes pod name). |
54 | | - */ |
55 | | - public String instanceId; |
56 | | - |
57 | | - /** |
58 | | - * General metrics for the application (Rest endpoints, JVM metrics, CGroup metrics etc). |
59 | | - */ |
60 | | - public List<MetricData> metrics = new ArrayList<>(); |
61 | | - |
62 | | - /** |
63 | | - * The database metrics. |
64 | | - */ |
65 | | - public List<MetricDbData> dbs = new ArrayList<>(); |
66 | | - |
67 | | - /** |
68 | | - * Optional extra resource attributes — typically parsed from the standard |
69 | | - * {@code OTEL_RESOURCE_ATTRIBUTES} env var by the client. Forwarded verbatim |
70 | | - * to the OTLP {@code resource.attributes} list. The reserved per-app fields |
71 | | - * ({@code service.name}, {@code service.version}, {@code service.instance.id}, |
72 | | - * {@code deployment.environment.name}) sourced from the dedicated header |
73 | | - * fields above take precedence over any matching keys here. |
74 | | - */ |
75 | | - public Map<String, String> resAttrs = new LinkedHashMap<>(); |
76 | | - |
| 63 | + public static MetricRequestBuilder builder() { |
| 64 | + return MetricRequestBuilder.builder(); |
| 65 | + } |
77 | 66 | } |
0 commit comments