-
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
Changes from 2 commits
92e875a
8f77c93
3ff052c
598274c
918dd7d
47376e2
f02a991
feeab39
f7ae601
bef0fc5
0672f42
f4a22f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,10 +34,10 @@ def resolve(pipelines_registry, pipeline_configs) | |||||||||
|
|
||||||||||
| if pipeline.nil? | ||||||||||
| actions << LogStash::PipelineAction::Create.new(pipeline_config, @metric) | ||||||||||
| else | ||||||||||
| if pipeline_config != pipeline.pipeline_config | ||||||||||
| actions << LogStash::PipelineAction::Reload.new(pipeline_config, @metric) | ||||||||||
| end | ||||||||||
| elsif pipeline_config != pipeline.pipeline_config | ||||||||||
| actions << LogStash::PipelineAction::Reload.new(pipeline_config, @metric) | ||||||||||
| elsif pipeline.crashed? && pipeline.configured_as_recoverable? | ||||||||||
| actions << LogStash::PipelineAction::Recover.new(pipeline_config, @metric) | ||||||||||
|
||||||||||
| elsif pipeline.crashed? && pipeline.configured_as_recoverable? | |
| actions << LogStash::PipelineAction::Recover.new(pipeline_config, @metric) | |
| elsif pipeline.crashed? && !pipeline.running? && pipeline.configured_as_recoverable? | |
| actions << LogStash::PipelineAction::Recover.new(pipeline_config, @metric) |
| 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 = | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.