vinothlk06 commented on issue #13501:
URL: https://github.com/apache/seatunnel/issues/13501#issuecomment-7221496800

   Thanks for reviewing and confirming the gap! Below is the proposed metric 
contract covering each point before opening a PR:
   
   ### 1. Master-Owned Fixed-Slot Gauges (Fixed vs. Dynamic & Tag Filtering)
   - **Metric families** (exported **only** by the active coordinator from a 
single consistent `ResourceManager` / `SlotService` snapshot, matching 
`GetOverviewOperation`):
     - `seatunnel_cluster_slots_total`
     - `seatunnel_cluster_slots_assigned`
     - `seatunnel_cluster_slots_unassigned`
     - **Invariant:** `seatunnel_cluster_slots_total == 
seatunnel_cluster_slots_assigned + seatunnel_cluster_slots_unassigned` holds 
within every scrape (`assigned = total - unassigned` from the same snapshot).
   - **Dynamic-slot mode (`dynamic-slot: true`):** Omit all three 
`seatunnel_cluster_slots_*` metric families completely rather than emitting `0`.
   - **Tag-filtered workers:** Keep the base `seatunnel_cluster_slots_*` gauges 
unlabeled for overall cluster capacity (all active workers, equivalent to 
`/overview` without tag filters). If per-tag visibility is needed, expose a 
separate optional family (e.g. 
`seatunnel_cluster_tag_slots_{total,assigned,unassigned}{tag_key="...",tag_value="..."}`)
 scoped only to configured worker `member-attributes` where the same `total == 
assigned + unassigned` invariant holds per tag pair (or leave tag-scoped gauges 
as a follow-up if preferred for v1).
   
   ### 2. Per-Job Series & Bounded Lifecycle (No Unbounded `job_name`-Only 
Labels)
   - **Immutable identity:** Every per-job series uses 
`{job_id="<immutable_job_id>", job_name="<job_name>"}` (never `job_name` 
alone), ensuring uniqueness even when multiple submissions share a `job_name`.
   - **Single series per `job_id` (value = state, not label):** Rather than 
putting `status` as a label (which leaves stale old-status series behind for 
Prometheus's staleness window on every transition), represent active job status 
via numeric state or boolean active gauges on `{job_id, job_name}`:
     - e.g., `seatunnel_job_state{job_id="...", job_name="..."}` (emitting 
active states such as `SCHEDULED`/`PENDING`, `RUNNING`, `FAILING`, 
`CANCELING`), or a dedicated `seatunnel_job_running` / `seatunnel_job_failing` 
gauge.
   - **Terminal & re-submission lifecycle (preventing stale alerts from 
retained history):**
     - **Do not export the `history-job-expire-minutes` (24h) archive** as 
Prometheus series—batch `FINISHED`/`CANCELED` jobs are omitted immediately once 
terminal so cardinality stays bounded to live/active jobs.
     - For **`FAILED`** jobs, if surfaced at all on the per-job family rather 
than solely via `job_count`, bound it strictly:
       1. Only emit a terminal `FAILED` sample for a short, bounded grace 
window (or until the `job_id` is archived/acknowledged) **and** immediately 
stop emitting/suppress it if a newer `job_id` with the same `job_name` becomes 
active (so re-submitting a failed job clears the old failure alert).
       2. Cap/evict any retained terminal entries independently of 
`history-job-expire-minutes` so historical failures never cause unbounded 
cardinality or stale alerts.
   - **Compatibility:** Existing `JobMetricExports` aggregate 
`job_count{type=...}` semantics remain completely unchanged.
   
   ### 3. Active Coordinator / Master Failover Behavior
   - **Leader-only export:** During each `MetricsServlet` scrape, only the 
active coordinator (`isMaster()` / active `CoordinatorService`) builds and 
exports the cluster-wide slot and per-job metric families from live coordinator 
state (no cross-scrape static/cached collector state).
   - **Standby masters & workers:** Omit these cluster-wide metric families 
completely so Prometheus never scrapes duplicate or conflicting values across 
master replicas.
   - **Failover transition:** When leadership changes, the demoted master stops 
emitting these families immediately (allowing Prometheus staleness cleanup), 
and the newly elected active master starts emitting them from its restored 
`CoordinatorService` / `ResourceManager` / `JobMaster` state.
   
   ### 4. Planned Validation for the PR
   Once this contract is agreed upon, the PR will include tests verifying:
   1. Both Prometheus text (`/hazelcast/rest/instance/metrics`) and OpenMetrics 
(`/hazelcast/rest/instance/openmetrics`) output formats.
   2. Fixed-slot allocation and release transitions (`total == assigned + 
unassigned`), plus complete omission of slot gauges when `dynamic-slot: true`.
   3. Job lifecycle transitions (`PENDING`/`RUNNING` -> `FAILING` -> `FAILED` 
-> re-submitted with a new `job_id`), confirming bounded cardinality and no 
stale alerts from job history.
   4. Multi-master coordinator failover, confirming only the active master 
exports cluster-wide series and existing `job_count` metrics remain unchanged.
   
   Please let me know if this contract looks good (and whether you prefer 
`seatunnel_job_state` to cover active states only or include bounded 
short-lived `FAILED` suppression on re-submission) so we can proceed with a 
focused PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to