Files
Roberto Jiménez Sánchez 6638c09e30 Provisioning: Add job operation metrics (#120147)
* Provisioning: Add job metrics for warnings, file ops, and resource ops

Introduce three new Prometheus metrics to the provisioning jobs package:
- `grafana_provisioning_jobs_warnings` (histogram): distribution of warning
  counts per sync by action and reason
- `grafana_provisioning_jobs_file_operations_total` (counter): file operations
  by action, operation, and reason
- `grafana_provisioning_jobs_resource_operations_total` (counter): resource
  operations by action, operation, reason, group, and kind

Wire the warnings histogram into the pull job via the progress recorder's
new WarningCounts() method, which counts warnings per reason as they are
recorded. The sync worker emits the histogram after each sync using the
actual job action, keeping the metrics generic across job types.

Also add the FolderMetadataConflict error type and warning reason as
plumbing for future conflict detection.

Made-with: Cursor

* Provisioning: Move metrics to driver, add errors histogram, add tests

- Pass *JobMetrics through driver constructors instead of
  SetWarningRecorder on the interface, so every job gets warning/error
  recording automatically without workers opting in.
- Add grafana_provisioning_jobs_errors histogram to track resource error
  count distribution per job run.
- Update metric descriptions to be generic for all job types.
- Add unit tests for FolderMetadataConflict, NewFolderManifest, and
  MissingFolderMetadata error formatting.

Made-with: Cursor

* Provisioning: Switch resource warnings/errors to counters, add resource prefix

- Rename metrics to grafana_provisioning_jobs_resource_warnings_total
  and grafana_provisioning_jobs_resource_errors_total.
- Change from histograms to counters since distribution per job run
  is not needed right now.
- Rename fields and methods to include Resource prefix for clarity.

Made-with: Cursor

* Provisioning: Restore worker_test.go to main (no changes needed)

Made-with: Cursor

* Provisioning: Fix gofmt formatting

Made-with: Cursor

* Provisioning: Emit resource metrics per-Record, remove file_operations metric

Move metric emission from Complete() snapshots to per-Record() Inc() calls,
simplifying the recording API and removing the need for snapshot/nil-guard
logic. Also remove the unused file_operations_total metric and WarningCounts
method.

Made-with: Cursor

* Provisioning: Consolidate resource metrics into single counter

Replace four separate metrics (resource_success_total, resource_warnings_total,
resource_errors_total, resource_operations_total) with a single unified
grafana_provisioning_jobs_resource_operations_total counter using an outcome
label to distinguish success/warning/error.

Made-with: Cursor

* Provisioning: Add typed constants for resource operation and outcome

Move ResourceOutcome and ResourceOperation types from metrics.go to
job_resource_result.go alongside other result types. Add OperationReplaced
constant and fileActionToOperation helper for mapping FileAction values.

Made-with: Cursor

* Provisioning: Use typed JobAction in RecordResourceOperation signature

Accept provisioning.JobAction instead of string for the action parameter.
Add OperationReplaced constant. Use existing provisioning constants in tests.

Made-with: Cursor

* Provisioning: Revert warningCounts back to resultReasons set

With per-Record metric emission we no longer need counts per reason.
Restore the original resultReasons map[string]struct{} from main.

Made-with: Cursor

* Provisioning: Remove trailing newline in progress_test.go

Made-with: Cursor

* Provisioning: Simplify RecordResourceOperation to accept JobResourceResult

Move outcome/operation/reason derivation into RecordResourceOperation so
callers just pass the action and result. Remove emitMetrics helper and
inline the call. Add OperationRenamed constant.

Made-with: Cursor

* Provisioning: Rename OperationNoop to OperationIgnored

Made-with: Cursor
2026-03-12 12:56:36 +00:00
..