Skip to content

Conversation

@moijes12
Copy link
Contributor

Changes Introduced

This patch parses the hg push resultset and handles cases where pushes are not present by raising an appropriate error and logging the error correctly.

Testing Information

  • A unit test has been added to tests/etl/test_push_loader.py to validate that the appropriate exception is raised when fetch_json returns a dict without pushes

This patch parses the hg push resultset and handles cases
where pushes are not present by raising an appropriate error
and logging the error correctly.
Copy link
Collaborator

@Archaeopteryx Archaeopteryx left a comment

Choose a reason for hiding this comment

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

Thank you for the patch. Please ask if there are questions about the review comments.

try:
data = fetch_json(url)
except Exception as e:
logger.exception("Failed fetching push JSON from %s for %s: %s", url, repository, e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use an f-string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in latest commit

pushes = data.get("pushes")

if not pushes or not isinstance(pushes, dict):
# Log deg info and raise error
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does deg mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a typo. I have corrected this in the latest commit.

{"url": url, "repository": repository, "data_keys": data_keys},
)
except Exception:
logger.debug("NewRelic event failed for malformed data")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please reword: NewRelic event failed for malformed Hg push data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I have made the updates.

try:
push = next(iter(pushes.values()))
except Exception as e:
logger.exception("Failed to extract first push from pushes for {respository} {url}:{e}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

f-string declaration missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

pass


class ResultsetFetchError(Exception):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use HgPushFetchError instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes implemented.

logger.exception("Failed fetching push JSON from %s for %s: %s", url, repository, e)
try:
newrelic.agent.record_custom_event(
"resultset_fetch_failure",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use hg_push_fetch_failure instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes Implemented

except Exception:
# NewRelic failures should not block ingestion
logger.debug("NewRelic event failed for fetch error")
raise ResultsetFetchError(f"Failed to fecth JSON from {url}: {e}") from e
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. This has been corrected.

)
try:
newrelic.agent.record_custom_event(
"resultset_fetch_malformed",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use hg_push_fetch_malformed instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Made the below changes to push_loader.py
* Used an f-string in line 267 to log exception
* Corrected comment where we log data in warning
* Used `NewRelic event failed for malformed Hg push data` in place of `NewRelic event failed for malformed data`
* Inserted f-string declaration and corrected typo in it too
* Renamed `ResultsetFetchError` to `HgPushFetchError`
* Renamed `resultset_fetch_failure` to `hg_push_fetch_failure`
* Corrected typo from `fecht` to `fetch`

Made the below change to test_push_loader.py
* Replace `ResultsetFetchError` with `HgPushFetchError`
@moijes12
Copy link
Contributor Author

moijes12 commented Nov 19, 2025

@Archaeopteryx

Thank you for reviewing it and providing your feedback.
Based on your feedback, I have made the below changes:

Changes to push_loader.py

  • Used an f-string in line 267 to log exception
  • Corrected comment where we log data in warning
  • Used NewRelic event failed for malformed Hg push data in place of NewRelic event failed for malformed data
  • Inserted f-string declaration where it was missing and corrected typo in it too
  • Renamed ResultsetFetchError to HgPushFetchError
  • Renamed resultset_fetch_failure to hg_push_fetch_failure
  • Renamed resultset_fetch_malformed to hg_push_fetch_malformed
  • Corrected typo from fecht to fetch

Change to test_push_loader.py

  • Replace ResultsetFetchError with HgPushFetchError

Copy link
Collaborator

@Archaeopteryx Archaeopteryx left a comment

Choose a reason for hiding this comment

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

Thank you.

@Archaeopteryx Archaeopteryx merged commit 4d72ce9 into mozilla:master Nov 21, 2025
6 checks passed
Archaeopteryx pushed a commit that referenced this pull request Nov 24, 2025
* Bug 1387418: Handle empty push resultset from hg

This patch parses the hg push resultset and handles cases
where pushes are not present by raising an appropriate error
and logging the error correctly.

* Bug 1387418: Address review comments

Made the below changes to push_loader.py
* Used an f-string in line 267 to log exception
* Corrected comment where we log data in warning
* Used `NewRelic event failed for malformed Hg push data` in place of `NewRelic event failed for malformed data`
* Inserted f-string declaration and corrected typo in it too
* Renamed `ResultsetFetchError` to `HgPushFetchError`
* Renamed `resultset_fetch_failure` to `hg_push_fetch_failure`
* Corrected typo from `fecht` to `fetch`

Made the below change to test_push_loader.py
* Replace `ResultsetFetchError` with `HgPushFetchError`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants