Skip to content

refactor(services): return the incident ID from CreateIncident#247

Open
nghiadaulau wants to merge 1 commit into
VersusControl:mainfrom
nghiadaulau:refactor/create-incident-returns-id
Open

refactor(services): return the incident ID from CreateIncident#247
nghiadaulau wants to merge 1 commit into
VersusControl:mainfrom
nghiadaulau:refactor/create-incident-returns-id

Conversation

@nghiadaulau

Copy link
Copy Markdown
Member

Summary

services.CreateIncident generated and persisted an incident ID but threw
it away, returning only error. This changes the signature to
(incidentID string, err error) and returns the ID, so callers can act on
the incident they just created.

Why

The service layer is the only place that holds the new incident's ID (the
worker's Emitter func type does not). Returning it here is the enabling
seam for follow-up work such as auto-analysis on emission, and is generally
useful (e.g. logging/linking the created incident).

The ID is returned even when a downstream channel or on-call step fails,
because the incident is persisted before fan-out and therefore exists; an
empty ID is returned only when no incident was created (provider
construction failed before persistence).

Changes

  • pkg/services/incident.go — signature + returns.
  • Call sites updated to the new signature (most ignore the ID with _,):
    cmd/main.go, pkg/controllers/incident.go (×4),
    pkg/controllers/sns.go (×2), pkg/services/agent.go.
  • No behavior change beyond the return value; no config/schema change.

Testing

  • TestCreateIncident_ReturnsPersistedID — loads a minimal config + memory
    store, creates an incident with all channels disabled, and asserts the
    returned ID is non-empty and resolves to the persisted record.
  • gofmt, go vet, go build ./..., go test -race ./pkg/services ./pkg/controllers
    green.

Checklist

  • Test for the new return value
  • All call sites updated; compiles
  • No config change; no user-facing behavior change
  • House conventions (refactor: prefix); CHANGELOG updated

CreateIncident generated and persisted an incident ID but discarded it,
returning only an error. Change the signature to (incidentID string, err
error) and return the ID so callers can act on the freshly created
incident (e.g. a future auto-analysis step keyed off the new ID).

The ID is returned even when a downstream channel or on-call step fails,
because the incident is persisted before fan-out and therefore exists; an
empty ID is returned only when no incident was created (provider
construction failed before persistence).

All call sites updated to the new signature (most ignore the ID):
cmd/main.go, pkg/controllers/incident.go (×4), pkg/controllers/sns.go (×2),
pkg/services/agent.go. Behavior is otherwise unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant