-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Support REACTIVE pipeline recovery with config.reload manager #18930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
92e875a
reload automatic: recover crashed pipelines during convergence
yaauie 8f77c93
recovery: add health report probes
yaauie 3ff052c
derp: fix invocation of failure_injector filter
yaauie 598274c
PR feedback:
yaauie 918dd7d
health tests: back out local branch changes
yaauie 47376e2
Merge remote-tracking branch 'upstream/main' into pipeline-recovery-r…
yaauie f02a991
update recovery test assertions to use new $match helper
yaauie feeab39
Apply suggestion from @yaauie
yaauie f7ae601
add logging, examples for `pipeline.recoverable` setting
yaauie bef0fc5
recovery: clean up old pipeline
yaauie 0672f42
recovery: keep only last 5min of recovery log
yaauie f4a22f7
Apply suggestions from code review
yaauie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
.buildkite/scripts/health-report-tests/tests/recovery-1m.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: "Recovery in 1min pipeline" | ||
| config: | ||
| - pipeline.id: crashy-recovery-pp | ||
| pipeline.recoverable: true | ||
| config.string: | | ||
| input { heartbeat { interval => 0.1 } } | ||
| filter { | ||
| ruby { | ||
| 'init' => '@crash_time = ::Time.now + 20' | ||
| 'code' => 'event.set("[@metadata][poison]", ::Time.now > @crash_time)' | ||
| } | ||
| if [@metadata][poison] { | ||
| failure_injector { crash_at => filter } | ||
| } | ||
| } | ||
| output { stdout {} } | ||
| conditions: | ||
| full_start_required: true | ||
| wait_seconds: 35 # anticipate one crash 20 seconds after pipeline starts, not enough for two. | ||
| expectation: | ||
| status: "yellow" | ||
| symptom: "1 indicator is concerning (`pipelines`)" | ||
| indicators: | ||
| pipelines: | ||
| status: "yellow" | ||
| symptom: "1 indicator is concerning (`crashy-recovery-pp`)" | ||
| indicators: | ||
| crashy-recovery-pp: | ||
| status: "yellow" | ||
| symptom: "The pipeline is concerning; 1 area is impacted and 1 diagnosis is available" | ||
| diagnosis: | ||
| - id: "logstash:health:pipeline:recovery:diagnosis:5m-recovery-recent" | ||
| cause: "pipeline has recovered from crashes 1 time in the last 5 minutes" | ||
| action: "inspect logs to determine source of crash" | ||
| impacts: | ||
| - id: "logstash:health:pipeline:recovery:impact:intermittent_processing" | ||
| severity: 2 | ||
| description: "pipeline recently recovered from a crash" | ||
| impact_areas: [ "pipeline_execution" ] | ||
| details: | ||
| status: | ||
| state: "RUNNING" | ||
| recovery_log: | ||
| - "$ISO8601$" | ||
yaauie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Licensed to Elasticsearch B.V. under one or more contributor | ||
| # license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright | ||
| # ownership. Elasticsearch B.V. licenses this file to you under | ||
| # the Apache License, Version 2.0 (the "License"); you may | ||
| # not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| require "logstash/pipeline_action/base" | ||
| require "logstash/java_pipeline" | ||
|
|
||
| module LogStash module PipelineAction | ||
| class Recover < Base | ||
| include LogStash::Util::Loggable | ||
|
|
||
| def initialize(pipeline_config, metric) | ||
| @pipeline_config = pipeline_config | ||
| @metric = metric | ||
| end | ||
|
|
||
| def pipeline_id | ||
| @pipeline_config.pipeline_id.to_sym | ||
| end | ||
|
|
||
| def to_s | ||
| "PipelineAction::Recover<#{pipeline_id}>" | ||
| end | ||
|
|
||
| def execute(agent, pipelines_registry) | ||
| old_pipeline = pipelines_registry.get_pipeline(pipeline_id) | ||
|
|
||
| # guard with descriptive errors | ||
| if old_pipeline.nil? | ||
| return new_failed_action("pipeline does not exist") | ||
| elsif old_pipeline.running? || !old_pipeline.crashed? | ||
| return new_failed_action("existing pipeline is not in a settled crashed state") | ||
yaauie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| elsif !old_pipeline.configured_as_recoverable? | ||
| return new_failed_action("existing pipeline not configured to be recoverable (see: `pipeline.recoverable`)") | ||
| elsif (nrp = old_pipeline.non_reloadable_plugins) && !nrp.empty? | ||
donoghuc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return new_failed_action("existing pipeline has non-reloadable plugins: #{nrp.map(&:readable_spec).join(', ')}") | ||
| end | ||
|
|
||
| begin | ||
| pipeline_validator = AbstractPipeline.new(@pipeline_config, nil, logger, nil) | ||
yaauie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| rescue => e | ||
| return ConvergeResult::FailedAction.from_exception(e) | ||
| end | ||
|
|
||
| if !pipeline_validator.reloadable? | ||
| return new_failed_action("Cannot recover pipeline, because the new pipeline is not reloadable") | ||
| end | ||
|
|
||
| logger.info("Recovering pipeline", "pipeline.id" => pipeline_id) | ||
|
|
||
| success = pipelines_registry.reload_pipeline(pipeline_id) do | ||
yaauie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # important NOT to explicitly return from block here | ||
| # the block must emit a success boolean value | ||
|
|
||
| # Then create a new pipeline | ||
| new_pipeline = LogStash::JavaPipeline.new(@pipeline_config, @metric, agent) | ||
| success = new_pipeline.start # block until the pipeline is correctly started or crashed | ||
|
|
||
| # return success and new_pipeline to registry reload_pipeline | ||
| [success, new_pipeline] | ||
| end | ||
| pipelines_registry.states.get(pipeline_id)&.mark_recovery if success | ||
|
|
||
| LogStash::ConvergeResult::ActionResult.create(self, success) | ||
| end | ||
|
|
||
| end | ||
| end; end | ||
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -539,6 +539,26 @@ public RubyArray nonReloadablePlugins(final ThreadContext context) { | |
| return result; | ||
| } | ||
|
|
||
| @JRubyMethod(name = "configured_queue_type") | ||
| public final IRubyObject configuredQueueType(final ThreadContext context) { | ||
| return getSetting(context, "queue.type"); | ||
| } | ||
|
|
||
| @JRubyMethod(name = "configured_as_recoverable?") | ||
| public final IRubyObject isConfiguredAsRecoverable(final ThreadContext context) { | ||
| final String recoverableSettingValue = getSetting(context, "pipeline.recoverable").asJavaString(); | ||
| final boolean result = switch (recoverableSettingValue) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we warn/fail loading when
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handled in f7ae601:
|
||
| case "true" -> true; | ||
yaauie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case "false" -> false; | ||
| case "auto" -> getSetting(context, "queue.type").asJavaString().equals(QueueFactoryExt.PERSISTED_TYPE); | ||
yaauie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| default -> { | ||
| LOGGER.warn("Unsupported `pipeline.recoverable` value {}; defaulting to `false`", recoverableSettingValue); | ||
| yield false; | ||
| } | ||
| }; | ||
| return result ? context.tru : context.fals; | ||
| } | ||
|
|
||
| @JRubyMethod(name = "collect_stats") | ||
| public final IRubyObject collectStats(final ThreadContext context) throws IOException { | ||
| final AbstractNamespacedMetricExt pipelineMetric = | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.