refactor(services): return the incident ID from CreateIncident#247
Open
nghiadaulau wants to merge 1 commit into
Open
refactor(services): return the incident ID from CreateIncident#247nghiadaulau wants to merge 1 commit into
nghiadaulau wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
services.CreateIncidentgenerated and persisted an incident ID but threwit away, returning only
error. This changes the signature to(incidentID string, err error)and returns the ID, so callers can act onthe incident they just created.
Why
The service layer is the only place that holds the new incident's ID (the
worker's
Emitterfunc type does not). Returning it here is the enablingseam 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._,):cmd/main.go,pkg/controllers/incident.go(×4),pkg/controllers/sns.go(×2),pkg/services/agent.go.Testing
TestCreateIncident_ReturnsPersistedID— loads a minimal config + memorystore, 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/controllersgreen.
Checklist
refactor:prefix); CHANGELOG updated