Commit 842d262
committed
feat(datastore): Add built-in Cloud Monitoring metrics export
Add a default-on, private OpenTelemetry SDK pipeline that automatically
exports Datastore client-side metrics to Google Cloud Monitoring without
requiring any user configuration.
Key additions:
- DatastoreBuiltInMetricsView: registers OTel views for metric renaming
(GAX prefix → custom.googleapis.com/internal/client), custom histogram
bucket boundaries, and an attribute allowlist that prevents unexpected
labels from reaching Cloud Monitoring
- DatastoreCloudMonitoringExporter: MetricExporter impl that batches
TimeSeries and calls MetricServiceClient.createTimeSeries(); graceful
degradation (logs warnings, never crashes); best-effort flush()
- DatastoreCloudMonitoringExporterUtils: converts OTel MetricData to
Cloud Monitoring TimeSeries protos
- BuiltInDatastoreMetricsProvider: creates a private OpenTelemetrySdk
per Datastore client; computes stable client_uid and client_name
attributes; registers a shutdown hook as a last-resort safety net
- CompositeDatastoreMetricsRecorder: fans out all record*() calls to
both the built-in and any user-provided backends simultaneously
- DatastoreMetricsRecorder.getInstance(): updated to composite factory
that wires up the built-in path (unless emulator or env-var disabled)
alongside any custom OTel backend; adds default close() for lifecycle
- OpenTelemetryDatastoreMetricsRecorder: add ownsOpenTelemetry flag and
close() so the built-in SDK is flushed when DatastoreImpl.close() runs
- DatastoreOpenTelemetryOptions: add exportBuiltinMetricsToGoogleCloudMonitoring
flag (default true) with @BetaApi getter and setter; clarify isEnabled()
Javadoc to note it does not cover the built-in path
- DatastoreImpl.close(): call getMetricsRecorder().close() after RPC
channel teardown so the built-in SDK flushes buffered metrics
- pom.xml: promote opentelemetry-sdk, opentelemetry-sdk-common, and
opentelemetry-sdk-metrics from test→compile scope; add
google-cloud-monitoring and proto-google-cloud-monitoring-v3 compile deps
- New tests: DatastoreCloudMonitoringExporterTest, BuiltInDatastoreMetricsProviderTest,
DatastoreMetricsRecorderTest (updated), DatastoreBuiltInAndCustomMetricsIT1 parent 0bf197b commit 842d262
14 files changed
Lines changed: 1958 additions & 38 deletions
File tree
- java-datastore/google-cloud-datastore
- src
- main/java/com/google/cloud/datastore
- telemetry
- test/java/com/google/cloud/datastore
- telemetry
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
200 | 199 | | |
201 | 200 | | |
202 | 201 | | |
203 | 202 | | |
204 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
205 | 213 | | |
206 | 214 | | |
207 | 215 | | |
| |||
216 | 224 | | |
217 | 225 | | |
218 | 226 | | |
219 | | - | |
220 | 227 | | |
221 | 228 | | |
222 | 229 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
165 | 175 | | |
166 | 176 | | |
167 | 177 | | |
168 | 178 | | |
169 | 179 | | |
170 | 180 | | |
171 | 181 | | |
| 182 | + | |
172 | 183 | | |
173 | 184 | | |
174 | 185 | | |
| |||
Lines changed: 81 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
| 37 | + | |
| 38 | + | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
34 | 42 | | |
35 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
36 | 50 | | |
37 | | - | |
| 51 | + | |
38 | 52 | | |
39 | 53 | | |
40 | 54 | | |
| |||
50 | 64 | | |
51 | 65 | | |
52 | 66 | | |
53 | | - | |
| 67 | + | |
54 | 68 | | |
55 | 69 | | |
56 | 70 | | |
57 | 71 | | |
58 | 72 | | |
59 | 73 | | |
60 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
61 | 95 | | |
62 | 96 | | |
63 | 97 | | |
64 | 98 | | |
65 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
66 | 105 | | |
67 | 106 | | |
68 | 107 | | |
69 | 108 | | |
70 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
71 | 115 | | |
72 | 116 | | |
73 | 117 | | |
| |||
77 | 121 | | |
78 | 122 | | |
79 | 123 | | |
| 124 | + | |
80 | 125 | | |
81 | 126 | | |
82 | 127 | | |
83 | 128 | | |
84 | 129 | | |
85 | 130 | | |
| 131 | + | |
86 | 132 | | |
87 | 133 | | |
88 | 134 | | |
89 | 135 | | |
90 | 136 | | |
91 | 137 | | |
| 138 | + | |
| 139 | + | |
92 | 140 | | |
93 | 141 | | |
94 | 142 | | |
95 | 143 | | |
96 | 144 | | |
97 | 145 | | |
98 | 146 | | |
| 147 | + | |
99 | 148 | | |
100 | 149 | | |
101 | 150 | | |
| |||
104 | 153 | | |
105 | 154 | | |
106 | 155 | | |
107 | | - | |
| 156 | + | |
108 | 157 | | |
109 | 158 | | |
110 | | - | |
| 159 | + | |
111 | 160 | | |
112 | 161 | | |
113 | 162 | | |
114 | 163 | | |
115 | 164 | | |
116 | 165 | | |
117 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
118 | 186 | | |
119 | 187 | | |
120 | | - | |
121 | | - | |
| 188 | + | |
| 189 | + | |
122 | 190 | | |
123 | 191 | | |
| 192 | + | |
124 | 193 | | |
125 | 194 | | |
126 | 195 | | |
| |||
129 | 198 | | |
130 | 199 | | |
131 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
132 | 206 | | |
133 | 207 | | |
134 | 208 | | |
| |||
0 commit comments