-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48623][CORE] Structured logging migrations [Part 2] #47256
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
25ca9a5
mdc migration
asl3 ccd768d
add logkeys
asl3 fec2433
style fix
asl3 a2de740
additional mdc migration
asl3 70eb929
add logkey
asl3 a7c887e
update logkey names
asl3 6a21ffc
restore logDebug
asl3 121fd6c
remove block logkey
asl3 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
additional mdc migration
- Loading branch information
commit a2de740966a6a51fee850675e94810e33a407d9a
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
asl3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF 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. | ||
| # | ||
|
|
||
| import os | ||
| import sys | ||
| import re | ||
| import glob | ||
|
|
||
| from sparktestsupport import SPARK_HOME | ||
|
|
||
| def main(): | ||
| log_pattern = r'log(?:Info|Warning|Error)\((.*?)\)' | ||
| inner_log_pattern = r'".*?"\.format\(.*\)|s?".*?(?:\$|\+(?!.*?[ |\t].*s?")).*' | ||
| compiled_inner_log_pattern = re.compile(inner_log_pattern, flags=re.DOTALL) | ||
|
|
||
| # Regex patterns for file paths to exclude from the Structured Logging style check | ||
| excluded_file_patterns = [ | ||
| '[Tt]est', | ||
| '/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala', | ||
| '/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala' | ||
| ] | ||
|
|
||
| nonmigrated_files = {} | ||
|
|
||
| scala_files = glob.glob(os.path.join(SPARK_HOME, '**', '*.scala'), recursive=True) | ||
|
|
||
| for file in scala_files: | ||
| skip_file = False | ||
| for exclude_pattern in excluded_file_patterns: | ||
| if re.search(exclude_pattern, file): | ||
| skip_file = True | ||
| break | ||
|
|
||
| if not skip_file: | ||
| with open(file, 'r') as f: | ||
| content = f.read() | ||
|
|
||
| log_statements = re.finditer(log_pattern, content, re.DOTALL) | ||
| # log_statements = [statement.group(1).strip() for statement in log_statements] | ||
|
|
||
| if log_statements: | ||
| nonmigrated_files[file] = [] | ||
| for log_statement in log_statements: | ||
| if compiled_inner_log_pattern.fullmatch(log_statement.group(1)): | ||
| start_pos = log_statement.start() | ||
| preceding_content = content[:start_pos] | ||
| line_number = preceding_content.count('\n') + 1 | ||
| start_char = start_pos - preceding_content.rfind('\n') - 1 | ||
| nonmigrated_files[file].append((line_number, start_char, log_statement.group(1))) | ||
|
|
||
| # for log_statement in log_statements: | ||
| # if compiled_inner_log_pattern.search(log_statement): | ||
| # nonmigrated_files[file].append() | ||
|
|
||
|
|
||
| # matches = list(pattern.finditer(content)) | ||
| # matches2 = pattern.findall(content) | ||
| # | ||
| # for m in matches2: | ||
| # print(f"****** ${m}") | ||
| # | ||
| # if matches: | ||
| # nonmigrated_files[file] = [] | ||
| # for match in matches: | ||
| # start_pos = match.start() | ||
| # preceding_content = content[:start_pos] | ||
| # line_number = preceding_content.count('\n') + 1 | ||
| # start_char = start_pos - preceding_content.rfind('\n') - 1 | ||
| # nonmigrated_files[file].append((line_number, start_char)) | ||
|
|
||
| if not nonmigrated_files: | ||
| print("Structured logging style check passed.") | ||
| sys.exit(0) | ||
| else: | ||
| for file_path, issues in nonmigrated_files.items(): | ||
| if issues: | ||
| print(file_path) | ||
| # for file_path, issues in nonmigrated_files.items(): | ||
| # for line_number, start_char in issues: | ||
| # pass | ||
| # print(f"[error] {file_path}:{line_number}:{start_char}") | ||
| # print("""[error]\t\tLogging message should use log"..." instead of s"..." and variables should be wrapped in `MDC`s. | ||
| # Refer to Structured Logging Framework guidelines in the file `internal/Logging.scala`.""") | ||
|
|
||
| sys.exit(-1) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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.