Skip to content

Commit 78a12ad

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 4f81f91 commit 78a12ad

File tree

7 files changed

+47
-25
lines changed

7 files changed

+47
-25
lines changed

docs/content/en/docs/documentation/observability.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,22 @@ The simplest way to create an instance:
8787

8888
```java
8989
MeterRegistry registry; // initialize your registry implementation
90-
Metrics metrics = MicrometerMetricsV2.newPerResourceCollectingMicrometerMetricsBuilder(registry).build();
90+
Metrics metrics = MicrometerMetricsV2.newMicrometerMetricsV2Builder(registry).build();
9191
```
9292

9393
Optionally, include a `namespace` tag on per-reconciliation counters (disabled by default to avoid unexpected
9494
cardinality increases in existing deployments):
9595

9696
```java
97-
Metrics metrics = MicrometerMetricsV2.newPerResourceCollectingMicrometerMetricsBuilder(registry)
97+
Metrics metrics = MicrometerMetricsV2.newMicrometerMetricsV2Builder(registry)
9898
.withNamespaceAsTag()
9999
.build();
100100
```
101101

102102
You can also supply a custom timer configuration for `reconciliations.execution.duration`:
103103

104104
```java
105-
Metrics metrics = MicrometerMetricsV2.newPerResourceCollectingMicrometerMetricsBuilder(registry)
105+
Metrics metrics = MicrometerMetricsV2.newMicrometerMetricsV2Builder(registry)
106106
.withExecutionTimerConfig(builder -> builder.publishPercentiles(0.5, 0.95, 0.99))
107107
.build();
108108
```

micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetricsV2.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public class MicrometerMetricsV2 implements Metrics {
8585
* @return a MicrometerMetricsV2 instance configured to not collect per-resource metrics
8686
* @see MicrometerMetricsV2Builder
8787
*/
88-
public static MicrometerMetricsV2Builder newPerResourceCollectingMicrometerMetricsBuilder(
89-
MeterRegistry registry) {
88+
public static MicrometerMetricsV2Builder newMicrometerMetricsV2Builder(MeterRegistry registry) {
9089
return new MicrometerMetricsV2Builder(registry);
9190
}
9291

@@ -176,9 +175,6 @@ public void receivedEvent(Event event, Map<String, Object> metadata) {
176175
if (resourceEvent.getAction() == ResourceAction.ADDED) {
177176
gauges.get(numberOfResourcesRefName(getControllerName(metadata))).incrementAndGet();
178177
}
179-
if (resourceEvent.getAction() == ResourceAction.DELETED) {
180-
gauges.get(numberOfResourcesRefName(getControllerName(metadata))).decrementAndGet();
181-
}
182178
var namespace = resourceEvent.getRelatedCustomResourceID().getNamespace().orElse(null);
183179
incrementCounter(
184180
EVENTS_RECEIVED,

observability/josdk-operator-metrics-dashboard.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@
195195
}
196196
}
197197
]
198+
},
199+
{
200+
"matcher": {
201+
"id": "byRegexp",
202+
"options": "Retries.*"
203+
},
204+
"properties": [
205+
{
206+
"id": "color",
207+
"value": {
208+
"fixedColor": "orange",
209+
"mode": "fixed"
210+
}
211+
}
212+
]
198213
}
199214
]
200215
},
@@ -239,9 +254,20 @@
239254
"legendFormat": "Failure - {{controller_name}}",
240255
"range": true,
241256
"refId": "B"
257+
},
258+
{
259+
"datasource": {
260+
"type": "prometheus",
261+
"uid": "prometheus"
262+
},
263+
"editorMode": "code",
264+
"expr": "sum(rate(reconciliations_retries_total{service_name=~\"$service_name\"}[5m])) by (controller_name)",
265+
"legendFormat": "Retries - {{controller_name}}",
266+
"range": true,
267+
"refId": "C"
242268
}
243269
],
244-
"title": "Reconciliation Success vs Failure Rate",
270+
"title": "Reconciliation Success / Failure / Retry Rate",
245271
"type": "timeseries"
246272
},
247273
{
@@ -609,7 +635,7 @@
609635
}
610636
]
611637
},
612-
"unit": "s"
638+
"unit": "ms"
613639
},
614640
"overrides": []
615641
},

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/monitoring/Metrics.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ default void receivedEvent(Event event, Map<String, Object> metadata) {}
5959
*/
6060
@Deprecated(forRemoval = true)
6161
default void reconcileCustomResource(
62-
HasMetadata resource, RetryInfo retryInfo, Map<String, Object> metadata) {
63-
submittedForReconciliation(resource, retryInfo, metadata);
64-
}
62+
HasMetadata resource, RetryInfo retryInfo, Map<String, Object> metadata) {}
6563

6664
/**
6765
* Called right before a resource is submitted to the ExecutorService for reconciliation.
@@ -71,7 +69,9 @@ default void reconcileCustomResource(
7169
* @param metadata metadata associated with the resource being processed
7270
*/
7371
default void submittedForReconciliation(
74-
HasMetadata resource, RetryInfo retryInfo, Map<String, Object> metadata) {}
72+
HasMetadata resource, RetryInfo retryInfo, Map<String, Object> metadata) {
73+
reconcileCustomResource(resource, retryInfo, metadata);
74+
}
7575

7676
default void reconciliationExecutionStarted(HasMetadata resource, Map<String, Object> metadata) {}
7777

@@ -100,14 +100,16 @@ default void failedReconciliation(
100100
* @param metadata metadata associated with the resource being processed
101101
*/
102102
default void successfullyFinishedReconciliation(
103-
HasMetadata resource, Map<String, Object> metadata) {}
103+
HasMetadata resource, Map<String, Object> metadata) {
104+
finishedReconciliation(resource, metadata);
105+
}
104106

105107
/**
106108
* Always called not only if successfully finished.
107109
*
108110
* @param resource the {@link ResourceID} associated with the resource being processed
109-
* @param retryInfo note that this retry info is in state after {@link RetryExecution#nextDelay()} is
110-
* called in case of exception.
111+
* @param retryInfo note that this retry info is in state after {@link RetryExecution#nextDelay()}
112+
* is called in case of exception.
111113
* @param metadata metadata associated with the resource being processed
112114
*/
113115
default void reconciliationExecutionFinished(
@@ -128,9 +130,7 @@ default void cleanupDoneFor(ResourceID resourceID, Map<String, Object> metadata)
128130
* @param metadata metadata associated with the resource being processed
129131
*/
130132
@Deprecated(forRemoval = true)
131-
default void finishedReconciliation(HasMetadata resource, Map<String, Object> metadata) {
132-
successfullyFinishedReconciliation(resource, metadata);
133-
}
133+
default void finishedReconciliation(HasMetadata resource, Map<String, Object> metadata) {}
134134

135135
/**
136136
* Encapsulates the information about a controller execution i.e. a call to either {@link

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private void submitReconciliationExecution(ResourceState state) {
180180
state.deleteEventPresent(),
181181
state.isDeleteFinalStateUnknown());
182182
state.unMarkEventReceived(triggerOnAllEvents());
183-
metrics.reconcileCustomResource(latest, state.getRetry(), metricsMetadata);
183+
metrics.submittedForReconciliation(latest, state.getRetry(), metricsMetadata);
184184
log.debug("Executing events for custom resource. Scope: {}", executionScope);
185185
executor.execute(new ReconcilerExecutor(resourceID, executionScope));
186186
} else {
@@ -286,7 +286,7 @@ synchronized void eventProcessingFinished(
286286
return;
287287
}
288288
cleanupOnSuccessfulExecution(executionScope);
289-
metrics.finishedReconciliation(executionScope.getResource(), metricsMetadata);
289+
metrics.successfullyFinishedReconciliation(executionScope.getResource(), metricsMetadata);
290290
if ((triggerOnAllEvents() && executionScope.isDeleteEvent())
291291
|| (!triggerOnAllEvents() && state.deleteEventPresent())) {
292292
cleanupForDeletedEvent(executionScope.getResourceID());

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ void startProcessedMarkedEventReceivedBefore() {
338338
eventProcessor.start();
339339

340340
verify(reconciliationDispatcherMock, timeout(100).times(1)).handleExecution(any());
341-
verify(metricsMock, times(1)).reconcileCustomResource(any(HasMetadata.class), isNull(), any());
341+
verify(metricsMock, times(1))
342+
.submittedForReconciliation(any(HasMetadata.class), isNull(), any());
342343
}
343344

344345
@Test

sample-operators/metrics-processing/src/main/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingSampleOperator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ public Duration step() {
123123
new ProcessorMetrics().bindTo(compositeRegistry);
124124
new UptimeMetrics().bindTo(compositeRegistry);
125125

126-
return MicrometerMetricsV2.newPerResourceCollectingMicrometerMetricsBuilder(compositeRegistry)
127-
.build();
126+
return MicrometerMetricsV2.newMicrometerMetricsV2Builder(compositeRegistry).build();
128127
}
129128

130129
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)