Skip to content

Introduce InputStopped Event to Distinguish Stop from Delete#25296

Open
patrickmann wants to merge 3 commits intomasterfrom
inputStopped
Open

Introduce InputStopped Event to Distinguish Stop from Delete#25296
patrickmann wants to merge 3 commits intomasterfrom
inputStopped

Conversation

@patrickmann
Copy link
Contributor

@patrickmann patrickmann commented Mar 11, 2026

Problem

Graylog emitted an InputDeleted event both when an input was stopped and when it was deleted. This made it impossible for downstream components to distinguish between the two lifecycle transitions.

Consequences:

  • MongoInputStatusService needed a database lookup workaround to determine if an input was actually deleted or just stopped (referenced in #7812)
  • StaticFieldFilter cleared its static field cache on stop, causing messages still draining from the journal to lose their static fields

Solution

Introduce a new InputStopped event so each lifecycle transition has its own event type:

  • Input stopped → emits InputStopped (input still exists in DB, just not running)
  • Input deleted → emits InputDeleted (input removed from DB)

Changes

New file

  • rest/models/system/inputs/responses/InputStopped.java — AutoValue event class matching the pattern of InputCreated, InputDeleted, InputSetup

Modified files

File Change
InputStatesResource.java stop() now returns InputStopped and posts it on the server EventBus instead of InputDeleted
InputEventListener.java Added inputStopped() handler that removes the input from the registry. Updated leaderChanged() to use InputStopped when a node loses leader role (inputs are stopped, not deleted)
MongoInputStatusService.java Removed the InputService dependency and the database-check workaround. handleInputDeleted() now unconditionally deletes the state record since it only fires on actual deletion

Test changes

File Change
InputEventListenerTest.java Added tests for inputStopped(): verifies registry removal and no-op when input not in registry
MongoInputStatusServiceTest.java Removed InputService mock and the "stop does nothing" workaround test. Simplified the delete test to verify unconditional state removal
StaticFieldFilterTest.java Added stoppedInputRetainsStaticFieldsForJournalMessages (stop preserves cache) and deletedInputClearsStaticFieldsCache (delete evicts cache)

Event architecture

There are two separate event types/buses:

  1. InputDeleted (AutoValue class) — posted on the local server EventBus. Consumed by InputEventListener, MongoInputStatusService, and StaticFieldFilter.
  2. InputDeletedEvent (record) — posted on the cluster EventBus. Consumed by ConfigurationStateUpdater, PipelineMetadataUpdater, and InputRoutingService. This was already correct (only fired from the actual delete endpoint) and was not changed.

Unchanged components

  • InputDeletedEvent (cluster event) — unchanged, only fires from InputsResource.terminate()
  • InputServiceImpl.destroy() — still posts InputDeleted via publishChange(), correct because it only runs on actual deletion
  • ConfigurationStateUpdater, PipelineMetadataUpdater, InputRoutingService — subscribe to InputDeletedEvent, not affected

How Tested

Unit tests and manual test per instructions in #23406

Motivation and Context

Resolves #7812
Resolves #23406

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have requested a documentation update.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@patrickmann patrickmann requested a review from Copilot March 11, 2026 14:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a dedicated InputStopped server event to distinguish “stop” from “delete”, preventing downstream consumers from treating a stopped input as deleted.

Changes:

  • Added new InputStopped AutoValue event model and updated InputStatesResource.stop() to emit it.
  • Updated InputEventListener to handle InputStopped and to use it when leadership is lost.
  • Simplified MongoInputStatusService deletion handling by removing the stop-vs-delete DB lookup workaround and updated tests accordingly.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
graylog2-server/src/main/java/org/graylog2/rest/resources/system/inputs/InputStatesResource.java Stop endpoint now returns/posts InputStopped instead of InputDeleted.
graylog2-server/src/main/java/org/graylog2/rest/models/system/inputs/responses/InputStopped.java New event model representing an input stop lifecycle transition.
graylog2-server/src/main/java/org/graylog2/inputs/InputEventListener.java Adds subscriber for InputStopped; leadership-loss path now triggers stop event instead of delete.
graylog2-server/src/main/java/org/graylog2/inputs/persistence/MongoInputStatusService.java Removes DB existence check workaround; InputDeleted now always deletes state.
graylog2-server/src/test/java/org/graylog2/inputs/persistence/MongoInputStatusServiceTest.java Updates tests to reflect unconditional deletion on InputDeleted and constructor signature change.
graylog2-server/src/test/java/org/graylog2/inputs/InputEventListenerTest.java Adds coverage for inputStopped() behavior.
graylog2-server/src/test/java/org/graylog2/filters/StaticFieldFilterTest.java Adds tests ensuring stop preserves cache, delete clears cache.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@patrickmann patrickmann marked this pull request as ready for review March 11, 2026 15:50
@patrickmann patrickmann requested a review from a team March 11, 2026 16:02
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.

Incorrect processing of journal messages for stopped inputs Need separate events for input stopped and input deleted

2 participants