-
Notifications
You must be signed in to change notification settings - Fork 141
[WIP] feat: Add counter-based validations and tests #1977
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -179,16 +179,34 @@ def _initialize_data_sources(self, stats_summary: str, lint_report: str, | |||||||||||||||||||||||||||||||||||||||||||||
| logging.warning("lint_report file exists but is empty: %s", | ||||||||||||||||||||||||||||||||||||||||||||||
| lint_report) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if counters_report and os.path.exists(counters_report) and os.path.getsize( | ||||||||||||||||||||||||||||||||||||||||||||||
| if counters_report: | ||||||||||||||||||||||||||||||||||||||||||||||
| self._load_counters(counters_report) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def _load_counters(self, counters_report: str): | ||||||||||||||||||||||||||||||||||||||||||||||
| """Loads counters from a CSV file and stores them in data_sources.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| if os.path.exists(counters_report) and os.path.getsize( | ||||||||||||||||||||||||||||||||||||||||||||||
| counters_report) > 0: | ||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||
| with open(counters_report, 'r') as f: | ||||||||||||||||||||||||||||||||||||||||||||||
| self.data_sources['counters'] = json.load(f) | ||||||||||||||||||||||||||||||||||||||||||||||
| df = pd.read_csv(counters_report) | ||||||||||||||||||||||||||||||||||||||||||||||
| def clean_key(x): | ||||||||||||||||||||||||||||||||||||||||||||||
| if not isinstance(x, str): | ||||||||||||||||||||||||||||||||||||||||||||||
| return x | ||||||||||||||||||||||||||||||||||||||||||||||
| if ':' in x: | ||||||||||||||||||||||||||||||||||||||||||||||
| x = x.split(':', 1)[1] | ||||||||||||||||||||||||||||||||||||||||||||||
| if '_' in x: | ||||||||||||||||||||||||||||||||||||||||||||||
| x = x.rsplit('_', 1)[-1] | ||||||||||||||||||||||||||||||||||||||||||||||
| return x | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| df['key'] = df['key'].apply(clean_key) | ||||||||||||||||||||||||||||||||||||||||||||||
| # Aggregate by summing if there are duplicates | ||||||||||||||||||||||||||||||||||||||||||||||
| df = df.groupby('key')['value'].sum().reset_index() | ||||||||||||||||||||||||||||||||||||||||||||||
| self.data_sources['counters'] = dict( | ||||||||||||||||||||||||||||||||||||||||||||||
| zip(df['key'], df['value'])) | ||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||||
| logging.error( | ||||||||||||||||||||||||||||||||||||||||||||||
| f"JSON parse error while reading counters report at {counters_report}: {e}" | ||||||||||||||||||||||||||||||||||||||||||||||
| f"CSV parse error while reading counters report at {counters_report}: {e}" | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+189
to
+208
Contributor
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. It is recommended to raise an exception if the counters report fails to parse, rather than just logging an error. Continuing with an empty
Suggested change
References
Comment on lines
+205
to
+208
Contributor
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. Avoid catching broad exceptions. It is better to catch specific errors that
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| elif counters_report and os.path.exists(counters_report): | ||||||||||||||||||||||||||||||||||||||||||||||
| elif os.path.exists(counters_report): | ||||||||||||||||||||||||||||||||||||||||||||||
| logging.warning("counters_report file exists but is empty: %s", | ||||||||||||||||||||||||||||||||||||||||||||||
| counters_report) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
clean_keylogic is too aggressive and will break counter names that contain underscores. For example, a counter namedrecords_count(following the recommended naming convention) would be incorrectly truncated tocount. Additionally,rsplit('_', 1)only works if the counter name itself has no underscores. A more robust approach would be to use a regular expression to strip the specific stage prefix pattern (e.g.,digit:string_).References