-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48592][INFRA] Add structured logging style script and GitHub workflow #47239
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 20 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6ef59e6
add structured logging style script and github workflow
asl3 d640b94
improve error message
asl3 b862228
match scala build error message
asl3 42de4c5
account for line breaks in regex match
asl3 95e86cc
fix script name
asl3 667bc58
update regex
asl3 58e763d
separate mono regex
asl3 0f26de8
add java files check
asl3 8959688
reformat python
asl3 0bd4e8a
check only scala files
asl3 c8b1b27
add CodeGenerator to exclude list due to large code formatter variable
asl3 22940d7
Merge branch 'master' into structuredlogstylescript
asl3 ae67d94
check if script exists
asl3 9f17a40
fix inner regex
asl3 4bb0ccf
add exclude file
asl3 97c3a74
revise error message
asl3 1b3950d
update error message
asl3 6f47405
check if file is a directory
asl3 dd0fb47
update regex
asl3 d6206a9
rename script
asl3 62e3c0d
style
asl3 e6d88b2
update gha yml
asl3 72f0c1b
line char max
asl3 7bdf67c
stylize the error message
asl3 bc400cc
Merge branch 'master' into structuredlogstylescript
asl3 bed4256
modify + regex
asl3 44ef1a5
Merge branch 'master' into structuredlogstylescript
asl3 20dd905
Merge branch 'master' into structuredlogstylescript
asl3 a253657
run script with python3.9
asl3 0c22383
update success condition check
asl3 2333388
lint fix
asl3 5f78989
reformat
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
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
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,92 @@ | ||
| #!/usr/bin/env python3 | ||
asl3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # | ||
| # 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 | ||
asl3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def main(): | ||
| log_pattern = r"log(?:Info|Warning|Error)\(.*?\)\n" | ||
| inner_log_pattern = r'".*?"\.format\(.*\)|s?".*?(?:\$|\+).*|[^"]+\+\s*".*?"' | ||
| compiled_inner_log_pattern = re.compile(inner_log_pattern) | ||
|
|
||
| # 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", | ||
| "streaming/src/main/scala/org/apache/spark/streaming/scheduler/JobScheduler.scala", | ||
| "sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala", | ||
| "core/src/main/scala/org/apache/spark/deploy/SparkSubmit.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 and not os.path.isdir(file): | ||
| with open(file, "r") as f: | ||
| content = f.read() | ||
|
|
||
| log_statements = re.finditer(log_pattern, content, re.DOTALL) | ||
|
|
||
| if log_statements: | ||
| nonmigrated_files[file] = [] | ||
| for log_statement in log_statements: | ||
| log_statement_str = log_statement.group(0).strip() | ||
| # trim first ( and last ) | ||
| first_paren_index = log_statement_str.find("(") | ||
| inner_log_statement = re.sub( | ||
| r"\s+", "", log_statement_str[first_paren_index + 1 : -1] | ||
| ) | ||
|
|
||
| if compiled_inner_log_pattern.fullmatch(inner_log_statement): | ||
| 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)) | ||
|
|
||
| if not nonmigrated_files: | ||
| print("Structured logging style check passed.") | ||
| sys.exit(0) | ||
| else: | ||
| for file_path, issues in nonmigrated_files.items(): | ||
| for line_number, start_char in issues: | ||
| print(f"[error] {file_path}:{line_number}:{start_char}") | ||
asl3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print( | ||
| """[error]\tPlease use the Structured Logging Framework for logging messages with variables. For example: log"...${MDC(TASK_ID, taskId)...". | ||
| Refer to the 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #!/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 | ||
|
|
||
|
|
||
| def main(): | ||
| log_pattern = r"log(?:Info|Warning|Error)\(.*?\)\n" | ||
| inner_log_pattern = r'".*?"\.format\(.*\)|s?".*?(?:\$|\+).*|[^"]+\+\s*".*?"' | ||
| compiled_inner_log_pattern = re.compile(inner_log_pattern) | ||
|
|
||
| # 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", | ||
| "streaming/src/main/scala/org/apache/spark/streaming/scheduler/JobScheduler.scala", | ||
| "sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala", | ||
| "core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala", | ||
| ] | ||
|
|
||
| nonmigrated_files = {} | ||
|
|
||
| scala_files = glob.glob(os.path.join("../", "**", "*.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 and not os.path.isdir(file): | ||
| with open(file, "r") as f: | ||
| content = f.read() | ||
|
|
||
| log_statements = re.finditer(log_pattern, content, re.DOTALL) | ||
|
|
||
| if log_statements: | ||
| nonmigrated_files[file] = [] | ||
| for log_statement in log_statements: | ||
| log_statement_str = log_statement.group(0).strip() | ||
| # trim first ( and last ) | ||
| first_paren_index = log_statement_str.find("(") | ||
| inner_log_statement = re.sub( | ||
| r"\s+", "", log_statement_str[first_paren_index + 1 : -1] | ||
| ) | ||
|
|
||
| if compiled_inner_log_pattern.fullmatch(inner_log_statement): | ||
| 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)) | ||
|
|
||
| if not nonmigrated_files: | ||
| print("Structured logging style check passed.", file=sys.stderr) | ||
| sys.exit(0) | ||
| else: | ||
| for file_path, issues in nonmigrated_files.items(): | ||
| for line_number, start_char in issues: | ||
| print(f"[error] {file_path}:{line_number}:{start_char}", file=sys.stderr) | ||
| print( | ||
| """[error]\tPlease use the Structured Logging Framework for logging messages with variables. For example: log"...${MDC(TASK_ID, taskId)...". | ||
| Refer to the guidelines in the file `internal/Logging.scala`.""", | ||
| file=sys.stderr, | ||
| ) | ||
|
|
||
| sys.exit(-1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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.