Skip to content

Commit 3d10fd4

Browse files
scotwellsclaude
andcommitted
feat: use forEach for status conditions
Replace verbose per-condition CEL filter/exists logic with the new forEach field on metric specs. Each status-condition generator now iterates object.status.conditions once and emits one series per element via item.*, rather than hardcoding individual condition types. The quota-grant-creation-policy generator previously had two separate metrics (Ready + ParentContextReady); these are collapsed into a single forEach metric. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 71528e9 commit 3d10fd4

2 files changed

Lines changed: 56 additions & 139 deletions

File tree

config/resource-metrics-policies/milo-metrics.yaml

Lines changed: 30 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,19 @@ spec:
158158
help: "Status conditions for IAM policy bindings"
159159
type: gauge
160160
metrics:
161-
- value: |
162-
object.status.conditions.exists(c, c.type == 'Ready') ?
163-
(object.status.conditions.filter(c, c.type == 'Ready')[0].status == 'True' ? 1.0 : 0.0) :
164-
0.0
161+
- forEach: "object.status.conditions"
162+
value: "item.status == 'True' ? 1.0 : 0.0"
165163
labels:
166164
- name: name
167165
value: "object.metadata.name"
168166
- name: namespace
169167
value: "object.metadata.namespace"
170168
- name: condition
171-
value: "'Ready'"
169+
value: "item.type"
172170
- name: reason
173-
value: |
174-
object.status.conditions.exists(c, c.type == 'Ready') ?
175-
object.status.conditions.filter(c, c.type == 'Ready')[0].reason : ''
171+
value: "item.reason"
176172
- name: status
177-
value: |
178-
object.status.conditions.exists(c, c.type == 'Ready') ?
179-
object.status.conditions.filter(c, c.type == 'Ready')[0].status : ''
173+
value: "item.status"
180174

181175
# iam.miloapis.com: ProtectedResource
182176
- name: iam-protected-resources-info
@@ -224,25 +218,19 @@ spec:
224218
help: "Status conditions for IAM protected resources"
225219
type: gauge
226220
metrics:
227-
- value: |
228-
object.status.conditions.exists(c, c.type == 'Ready') ?
229-
(object.status.conditions.filter(c, c.type == 'Ready')[0].status == 'True' ? 1.0 : 0.0) :
230-
0.0
221+
- forEach: "object.status.conditions"
222+
value: "item.status == 'True' ? 1.0 : 0.0"
231223
labels:
232224
- name: name
233225
value: "object.metadata.name"
234226
- name: namespace
235227
value: "object.metadata.namespace"
236228
- name: condition
237-
value: "'Ready'"
229+
value: "item.type"
238230
- name: reason
239-
value: |
240-
object.status.conditions.exists(c, c.type == 'Ready') ?
241-
object.status.conditions.filter(c, c.type == 'Ready')[0].reason : ''
231+
value: "item.reason"
242232
- name: status
243-
value: |
244-
object.status.conditions.exists(c, c.type == 'Ready') ?
245-
object.status.conditions.filter(c, c.type == 'Ready')[0].status : ''
233+
value: "item.status"
246234

247235
# iam.miloapis.com: Role
248236
- name: iam-roles-info
@@ -290,25 +278,19 @@ spec:
290278
help: "Status conditions for IAM roles"
291279
type: gauge
292280
metrics:
293-
- value: |
294-
object.status.conditions.exists(c, c.type == 'Ready') ?
295-
(object.status.conditions.filter(c, c.type == 'Ready')[0].status == 'True' ? 1.0 : 0.0) :
296-
0.0
281+
- forEach: "object.status.conditions"
282+
value: "item.status == 'True' ? 1.0 : 0.0"
297283
labels:
298284
- name: name
299285
value: "object.metadata.name"
300286
- name: namespace
301287
value: "object.metadata.namespace"
302288
- name: condition
303-
value: "'Ready'"
289+
value: "item.type"
304290
- name: reason
305-
value: |
306-
object.status.conditions.exists(c, c.type == 'Ready') ?
307-
object.status.conditions.filter(c, c.type == 'Ready')[0].reason : ''
291+
value: "item.reason"
308292
- name: status
309-
value: |
310-
object.status.conditions.exists(c, c.type == 'Ready') ?
311-
object.status.conditions.filter(c, c.type == 'Ready')[0].status : ''
293+
value: "item.status"
312294

313295
# iam.miloapis.com: UserInvitation
314296
- name: iam-user-invitations-info
@@ -502,25 +484,19 @@ spec:
502484
help: "Status conditions for resource manager organization memberships"
503485
type: gauge
504486
metrics:
505-
- value: |
506-
object.status.conditions.exists(c, c.type == 'Ready') ?
507-
(object.status.conditions.filter(c, c.type == 'Ready')[0].status == 'True' ? 1.0 : 0.0) :
508-
0.0
487+
- forEach: "object.status.conditions"
488+
value: "item.status == 'True' ? 1.0 : 0.0"
509489
labels:
510490
- name: name
511491
value: "object.metadata.name"
512492
- name: namespace
513493
value: "object.metadata.namespace"
514494
- name: condition
515-
value: "'Ready'"
495+
value: "item.type"
516496
- name: reason
517-
value: |
518-
object.status.conditions.exists(c, c.type == 'Ready') ?
519-
object.status.conditions.filter(c, c.type == 'Ready')[0].reason : ''
497+
value: "item.reason"
520498
- name: status
521-
value: |
522-
object.status.conditions.exists(c, c.type == 'Ready') ?
523-
object.status.conditions.filter(c, c.type == 'Ready')[0].status : ''
499+
value: "item.status"
524500

525501
# resourcemanager.miloapis.com: Organization
526502
- name: resourcemanager-organizations-info
@@ -570,25 +546,19 @@ spec:
570546
help: "Status conditions for resource manager organizations"
571547
type: gauge
572548
metrics:
573-
- value: |
574-
object.status.conditions.exists(c, c.type == 'Ready') ?
575-
(object.status.conditions.filter(c, c.type == 'Ready')[0].status == 'True' ? 1.0 : 0.0) :
576-
0.0
549+
- forEach: "object.status.conditions"
550+
value: "item.status == 'True' ? 1.0 : 0.0"
577551
labels:
578552
- name: name
579553
value: "object.metadata.name"
580554
- name: namespace
581555
value: "object.metadata.namespace"
582556
- name: condition
583-
value: "'Ready'"
557+
value: "item.type"
584558
- name: reason
585-
value: |
586-
object.status.conditions.exists(c, c.type == 'Ready') ?
587-
object.status.conditions.filter(c, c.type == 'Ready')[0].reason : ''
559+
value: "item.reason"
588560
- name: status
589-
value: |
590-
object.status.conditions.exists(c, c.type == 'Ready') ?
591-
object.status.conditions.filter(c, c.type == 'Ready')[0].status : ''
561+
value: "item.status"
592562

593563
# resourcemanager.miloapis.com: Project
594564
- name: resourcemanager-projects-info
@@ -640,22 +610,16 @@ spec:
640610
help: "Status conditions for resource manager projects"
641611
type: gauge
642612
metrics:
643-
- value: |
644-
object.status.conditions.exists(c, c.type == 'Ready') ?
645-
(object.status.conditions.filter(c, c.type == 'Ready')[0].status == 'True' ? 1.0 : 0.0) :
646-
0.0
613+
- forEach: "object.status.conditions"
614+
value: "item.status == 'True' ? 1.0 : 0.0"
647615
labels:
648616
- name: name
649617
value: "object.metadata.name"
650618
- name: namespace
651619
value: "object.metadata.namespace"
652620
- name: condition
653-
value: "'Ready'"
621+
value: "item.type"
654622
- name: reason
655-
value: |
656-
object.status.conditions.exists(c, c.type == 'Ready') ?
657-
object.status.conditions.filter(c, c.type == 'Ready')[0].reason : ''
623+
value: "item.reason"
658624
- name: status
659-
value: |
660-
object.status.conditions.exists(c, c.type == 'Ready') ?
661-
object.status.conditions.filter(c, c.type == 'Ready')[0].status : ''
625+
value: "item.status"

config/resource-metrics-policies/milo-quota-metrics.yaml

Lines changed: 26 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,17 @@ spec:
202202
help: "Status conditions for quota claim creation policies"
203203
type: gauge
204204
metrics:
205-
- value: |
206-
object.status.conditions.exists(c, c.type == 'Ready') ?
207-
(object.status.conditions.filter(c, c.type == 'Ready')[0].status == 'True' ? 1.0 : 0.0) :
208-
0.0
205+
- forEach: "object.status.conditions"
206+
value: "item.status == 'True' ? 1.0 : 0.0"
209207
labels:
210208
- name: name
211209
value: "object.metadata.name"
212210
- name: condition
213-
value: "'Ready'"
211+
value: "item.type"
214212
- name: reason
215-
value: |
216-
object.status.conditions.exists(c, c.type == 'Ready') ?
217-
object.status.conditions.filter(c, c.type == 'Ready')[0].reason : ''
213+
value: "item.reason"
218214
- name: status
219-
value: |
220-
object.status.conditions.exists(c, c.type == 'Ready') ?
221-
object.status.conditions.filter(c, c.type == 'Ready')[0].status : ''
215+
value: "item.status"
222216

223217
- name: quota-claim-creation-policy-enabled
224218
resource:
@@ -292,7 +286,7 @@ spec:
292286
- name: parent_context_kind
293287
value: "has(object.spec.target) && has(object.spec.target.parentContext) ? object.spec.target.parentContext.kind : ''"
294288

295-
- name: quota-grant-creation-policy-status-condition-ready
289+
- name: quota-grant-creation-policy-status-condition
296290
resource:
297291
group: quota.miloapis.com
298292
version: v1alpha1
@@ -302,40 +296,17 @@ spec:
302296
help: "Status conditions for quota grant creation policies"
303297
type: gauge
304298
metrics:
305-
- value: |
306-
object.status.conditions.exists(c, c.type == 'Ready') ?
307-
(object.status.conditions.filter(c, c.type == 'Ready')[0].status == 'True' ? 1.0 : 0.0) :
308-
0.0
309-
labels:
310-
- name: name
311-
value: "object.metadata.name"
312-
- name: condition
313-
value: "'Ready'"
314-
- name: reason
315-
value: |
316-
object.status.conditions.exists(c, c.type == 'Ready') ?
317-
object.status.conditions.filter(c, c.type == 'Ready')[0].reason : ''
318-
- name: status
319-
value: |
320-
object.status.conditions.exists(c, c.type == 'Ready') ?
321-
object.status.conditions.filter(c, c.type == 'Ready')[0].status : ''
322-
- value: |
323-
object.status.conditions.exists(c, c.type == 'ParentContextReady') ?
324-
(object.status.conditions.filter(c, c.type == 'ParentContextReady')[0].status == 'True' ? 1.0 : 0.0) :
325-
0.0
299+
- forEach: "object.status.conditions"
300+
value: "item.status == 'True' ? 1.0 : 0.0"
326301
labels:
327302
- name: name
328303
value: "object.metadata.name"
329304
- name: condition
330-
value: "'ParentContextReady'"
305+
value: "item.type"
331306
- name: reason
332-
value: |
333-
object.status.conditions.exists(c, c.type == 'ParentContextReady') ?
334-
object.status.conditions.filter(c, c.type == 'ParentContextReady')[0].reason : ''
307+
value: "item.reason"
335308
- name: status
336-
value: |
337-
object.status.conditions.exists(c, c.type == 'ParentContextReady') ?
338-
object.status.conditions.filter(c, c.type == 'ParentContextReady')[0].status : ''
309+
value: "item.status"
339310

340311
- name: quota-grant-creation-policy-enabled
341312
resource:
@@ -425,25 +396,19 @@ spec:
425396
help: "Status conditions for quota resource claims"
426397
type: gauge
427398
metrics:
428-
- value: |
429-
object.status.conditions.exists(c, c.type == 'Granted') ?
430-
(object.status.conditions.filter(c, c.type == 'Granted')[0].status == 'True' ? 1.0 : 0.0) :
431-
0.0
399+
- forEach: "object.status.conditions"
400+
value: "item.status == 'True' ? 1.0 : 0.0"
432401
labels:
433402
- name: name
434403
value: "object.metadata.name"
435404
- name: namespace
436405
value: "object.metadata.namespace"
437406
- name: condition
438-
value: "'Granted'"
407+
value: "item.type"
439408
- name: reason
440-
value: |
441-
object.status.conditions.exists(c, c.type == 'Granted') ?
442-
object.status.conditions.filter(c, c.type == 'Granted')[0].reason : ''
409+
value: "item.reason"
443410
- name: status
444-
value: |
445-
object.status.conditions.exists(c, c.type == 'Granted') ?
446-
object.status.conditions.filter(c, c.type == 'Granted')[0].status : ''
411+
value: "item.status"
447412

448413
- name: quota-resource-claim-observed-generation
449414
resource:
@@ -514,25 +479,19 @@ spec:
514479
help: "Status conditions for quota resource grants"
515480
type: gauge
516481
metrics:
517-
- value: |
518-
object.status.conditions.exists(c, c.type == 'Active') ?
519-
(object.status.conditions.filter(c, c.type == 'Active')[0].status == 'True' ? 1.0 : 0.0) :
520-
0.0
482+
- forEach: "object.status.conditions"
483+
value: "item.status == 'True' ? 1.0 : 0.0"
521484
labels:
522485
- name: name
523486
value: "object.metadata.name"
524487
- name: namespace
525488
value: "object.metadata.namespace"
526489
- name: condition
527-
value: "'Active'"
490+
value: "item.type"
528491
- name: reason
529-
value: |
530-
object.status.conditions.exists(c, c.type == 'Active') ?
531-
object.status.conditions.filter(c, c.type == 'Active')[0].reason : ''
492+
value: "item.reason"
532493
- name: status
533-
value: |
534-
object.status.conditions.exists(c, c.type == 'Active') ?
535-
object.status.conditions.filter(c, c.type == 'Active')[0].status : ''
494+
value: "item.status"
536495

537496
- name: quota-resource-grant-observed-generation
538497
resource:
@@ -611,23 +570,17 @@ spec:
611570
help: "Status conditions for quota resource registrations"
612571
type: gauge
613572
metrics:
614-
- value: |
615-
object.status.conditions.exists(c, c.type == 'Active') ?
616-
(object.status.conditions.filter(c, c.type == 'Active')[0].status == 'True' ? 1.0 : 0.0) :
617-
0.0
573+
- forEach: "object.status.conditions"
574+
value: "item.status == 'True' ? 1.0 : 0.0"
618575
labels:
619576
- name: name
620577
value: "object.metadata.name"
621578
- name: condition
622-
value: "'Active'"
579+
value: "item.type"
623580
- name: reason
624-
value: |
625-
object.status.conditions.exists(c, c.type == 'Active') ?
626-
object.status.conditions.filter(c, c.type == 'Active')[0].reason : ''
581+
value: "item.reason"
627582
- name: status
628-
value: |
629-
object.status.conditions.exists(c, c.type == 'Active') ?
630-
object.status.conditions.filter(c, c.type == 'Active')[0].status : ''
583+
value: "item.status"
631584

632585
- name: quota-resource-registration-observed-generation
633586
resource:

0 commit comments

Comments
 (0)