fix(observer): log_for_query_filter drops every log (undefined self, swallowed NameError) - #200
Open
Tai An (Anai-Guo) wants to merge 1 commit into
Open
Conversation
log_for_query_filter is a module-level function, but its body reads `self.log_pod_list`. `self` is not defined there, so evaluating it raises NameError on the first log -- and the bare `except Exception: continue` right below swallows it and skips that log. Every log takes the same path, so the filter returns an empty list no matter what Elasticsearch returned, and LogAPI.query() always yields nothing. Take the pod list as a parameter and pass self.log_pod_list from the one call site in LogAPI.query(), which is the value the function was reaching for. Signed-off-by: Tai An <antai12232931@outlook.com>
Contributor
There was a problem hiding this comment.
This fixes a nasty little bug in log_for_query_filter. The function was calling self.log_pod_list even though it's a standalone function with no access to self — so every single log hit a NameError, got swallowed by the broad except Exception: continue, and the function silently returned an empty list. No crash, no warning, just zero logs coming back. The fix is clean: it passes log_pod_list in as a parameter and uses it directly.
🤖 Generated with DeepSeek
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.
The bug
log_for_query_filterinaiopslab/observer/log_api.pyis a module-level function, but its body readsself.log_pod_list:selfis not a parameter, not a global, and not a closure variable, so evaluating it raisesNameErroron the very first log. The bareexcept Exception: continueimmediately below catches it and skips that log — and since every log takes exactly the same path, the function returns an empty list regardless of what Elasticsearch returned.It has one caller, at the end of
LogAPI.query():So
LogAPI.query()always yields nothing. Because the exception is swallowed, there is no traceback and no log line — the query just silently comes back empty, which reads as "Elasticsearch had no matching logs" rather than as a bug.python -m pyflakesonmainflags it:The fix
Take the pod list as a parameter and pass
self.log_pod_listfrom the one call site — that is the value the function was reaching for, and it is already available inLogAPI.query().Verification
log_for_query_filterwas extracted withastand run directly (no elasticsearch/kubernetes imports needed) on sample ES hits, two of which are from monitored pods:The
loadgenerator-9hit is still filtered out, which is the intended behaviour —initialize_pod_and_service_lists()deliberately excludesloadgenerator-*andredis-cartpods.One related note (not changed here)
log_processing_online_boutique(line 330) has the identical problem — module-level, readsself.log_pod_listat line 339, inside atry/except Exception: continue. I left it alone because its only call site is commented out (line 138), so it is not reachable today. Happy to fold the same change into this PR if you'd like it fixed before that line is ever re-enabled.🤖 Generated with Claude Code