Skip to content

Conversation

kaisecheng
Copy link
Contributor

@kaisecheng kaisecheng commented Feb 11, 2025

Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035

@kaisecheng
Copy link
Contributor Author

es-output 12.0.2 leaves the caller to make the decision on what to consider a bad response code error. Although this PR allow CPM to handle 404 response gracefully with user-friendly log, the released versions with es-output 12.0.2 are still getting the stack trace in log

An alternative solution is to restore 404 behaviour in es-output.

@donoghuc
Copy link
Member

Out of curiousity... Why not handle the 404 in fetch_config?

def fetch_config(es_version, pipeline_ids, client)
or whatever class is using the client directly?

@kaisecheng
Copy link
Contributor Author

Why not handle the 404 in fetch_config?

To handle in fetcher, it requires changes on SystemIndicesFetcher, LegacyHiddenIndicesFetcher, the internal state of @pipelines and unwrap the BadResponseCodeError. As we need to maintain logstash core to work with all supported es-output versions, keeping the minimum change in this case would be easier for maintainer

Thanks for review. The pipelines should be Array

@kaisecheng kaisecheng requested a review from donoghuc February 11, 2025 19:15
@donoghuc
Copy link
Member

I'm not quite sure I'm following your comment here #17052 (comment).

I think that the behavior we are trying to preserve is that fetch_config will just be an "empty" pipeline if there is a 404.

def fetch_config(es_version, pipeline_ids, client)
es_supports_pipeline_wildcard_search = es_supports_pipeline_wildcard_search?(es_version)
retry_handler = ::LogStash::Helpers::LoggableTry.new(logger, 'fetch pipelines from Central Management')
response = retry_handler.try(10.times, ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError) {
path = es_supports_pipeline_wildcard_search ?
"#{SYSTEM_INDICES_API_PATH}?id=#{ERB::Util.url_encode(pipeline_ids.join(","))}" :
"#{SYSTEM_INDICES_API_PATH}/"
client.get(path)
}
if response["error"]
raise ElasticsearchSource::RemoteConfigError, "Cannot find find configuration for pipeline_id: #{pipeline_ids}, server returned status: `#{response["status"]}`, message: `#{response["error"]}`"
( i had the wrong fetch_config linked in #17052 (comment) ). It seems to me like the responsibility of that is fully in the fetch_config method as it is the consumer of the plugin's client. Moving the required knowledge of an error type defined in logstash-output-elasticsearch to the source loader seems to perpetuate the underlying tech debt issue of using the plugin's client rather than our own.

It seems to me that the path forward would be to for now fix up instances of fetch_config to handle 404 (a rescue there should be forward/backward compatible) and then when we move away from using the plugin's client we just have one file to refactor?

@kaisecheng
Copy link
Contributor Author

I see what you mean. We have two fetchers using client to get data, SystemIndicesFetcher for 7.10+ and LegacyHiddenIndicesFetcher for 6 & 7. The code you linked is SystemIndicesFetcher. I would avoid touching any part of LegacyHiddenIndicesFetcher, as it requires me to test against ES 6 & 7 and I know the returned value is neither an empty pipeline {} nor []

agree your point that it is better to put try catch block close to the caller class. In this case, it should be inside xpack.
I moved the block to xpack and certainly need to more tests to verify as my memory about system indices is very weak and not up-to-date.

when we move away from using the plugin's client we just have one file to refactor?

probably not, we have another use case licence checker which is also in xpack

begin
fetcher.fetch_config(es_version, pipeline_ids, client)
rescue LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
return [] if e.response_code == 404
Copy link
Member

Choose a reason for hiding this comment

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

Will this early return cause a difference in behavior whereby the @cached_pipelines are not updated on 404 now? Does that matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't matter. The pipeline is empty anyway and the cache is purely optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reviewing the flow, I decide to remove the cache because the existing pipelines can keep running without cache when error is raised. It was there to prevent cleaning up the running pipelines.

@donoghuc
Copy link
Member

Thanks for the explanation. Given this is a short term solution anyway with the intent to get a dedicated client I think its OK if we are concerned about the risks/burdens you mentioned.

@elastic-sonarqube
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@elasticmachine
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

History

@kaisecheng kaisecheng requested a review from donoghuc February 12, 2025 15:23
Copy link
Member

@donoghuc donoghuc left a comment

Choose a reason for hiding this comment

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

I couldn't quite trace back the git history for the addition of the cache (dead ends with a generic "migrate x-pack" bulk commit 93cad10.

Its kind of hard to trace through exactly what all calls this (or how many times), but i dont see anything egregiously consuming it.

@kaisecheng kaisecheng merged commit e896cd7 into elastic:main Feb 17, 2025
7 checks passed
@kaisecheng
Copy link
Contributor Author

@logstashmachine backport 9.0

@kaisecheng
Copy link
Contributor Author

@logstashmachine backport 8.18

github-actions bot pushed a commit that referenced this pull request Feb 17, 2025
Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035
(cherry picked from commit e896cd7)
github-actions bot pushed a commit that referenced this pull request Feb 17, 2025
Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035
(cherry picked from commit e896cd7)
@kaisecheng
Copy link
Contributor Author

@logstashmachine backport 8.17

@kaisecheng
Copy link
Contributor Author

@logstashmachine backport 8.16

github-actions bot pushed a commit that referenced this pull request Feb 17, 2025
Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035
(cherry picked from commit e896cd7)
github-actions bot pushed a commit that referenced this pull request Feb 17, 2025
Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035
(cherry picked from commit e896cd7)
kaisecheng added a commit that referenced this pull request Feb 17, 2025
…17097)

Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035
(cherry picked from commit e896cd7)

Co-authored-by: kaisecheng <[email protected]>
kaisecheng added a commit that referenced this pull request Feb 17, 2025
…17098)

Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035
(cherry picked from commit e896cd7)

Co-authored-by: kaisecheng <[email protected]>
kaisecheng added a commit that referenced this pull request Feb 17, 2025
…17099)

Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035
(cherry picked from commit e896cd7)

Co-authored-by: kaisecheng <[email protected]>
kaisecheng added a commit that referenced this pull request Feb 17, 2025
…17100)

Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: #17035
(cherry picked from commit e896cd7)

Co-authored-by: kaisecheng <[email protected]>
v1v pushed a commit to v1v/logstash that referenced this pull request Feb 25, 2025
)

Starting from es-output 12.0.2, a 404 response is treated as an error. Previously, central pipeline management considered 404 as an empty pipeline, not an error.

This commit restores the expected behavior by handling 404 gracefully and logs a user-friendly message.
It also removes the redundant cache of pipeline in CPM

Fixes: elastic#17035
v1v added a commit to v1v/logstash that referenced this pull request Feb 25, 2025
…gify

* upstream/main: (27 commits)
  Add Windows 2025 to CI (elastic#17133)
  Update container acceptance tests with stdout/stderr changes (elastic#17138)
  entrypoint: avoid polluting stdout (elastic#17125)
  Fix acceptance test assertions for updated plugin remove (elastic#17126)
  Fix acceptance test assertions for updated plugin `remove` (elastic#17122)
  plugins: improve `remove` command to support multiple plugins (elastic#17030)
  spec: improve ls2ls spec (elastic#17114)
  allow concurrent Batch deserialization (elastic#17050)
  CPM handle 404 response gracefully with user-friendly log (elastic#17052)
  qa: use clean expansion of LS tarball per fixture instance (elastic#17082)
  Allow capturing heap dumps in DRA BK jobs (elastic#17081)
  Use centralized source of truth for active branches (elastic#17063)
  Update logstash_releases.json (elastic#17055)
  fix logstash-keystore to accept spaces in values when added via stdin (elastic#17039)
  Don't honor VERSION_QUALIFIER if set but empty (elastic#17032)
  Release note placeholder might be empty, making parsing lines nil tolerant. (elastic#17026)
  Fix BufferedTokenizer to properly resume after a buffer full condition respecting the encoding of the input string (elastic#16968)
  Add short living 9.0 next and update main in CI release version definition. (elastic#17008)
  Core version bump to 9.1.0 (elastic#16991)
  Add 9.0 branch to the CI branches definition (elastic#16997)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

empty pipeline returns from CPM gives 404

3 participants