Page MenuHomeSoftware Heritage

D7283.diff
No OneTemporary

D7283.diff

diff --git a/swh/icinga_plugins/deposit.py b/swh/icinga_plugins/deposit.py
--- a/swh/icinga_plugins/deposit.py
+++ b/swh/icinga_plugins/deposit.py
@@ -97,6 +97,9 @@
def main(self):
start_time = time.time()
+ start_datetime = datetime.datetime.fromtimestamp(
+ start_time, tz=datetime.timezone.utc
+ )
metrics = {}
# Upload the archive and metadata
@@ -170,18 +173,26 @@
)
return 2
- # Get metadata from swh-web
+ # Get metadata list from swh-web
metadata_objects = requests.get(
f"{self.api_url}/api/1/raw-extrinsic-metadata/swhid/{swhid}/"
f"?authority=deposit_client%20{self._provider_url}"
).json()
expected_origin = f"{self._provider_url}/{self._slug}"
- origins = [d.get("origin") for d in metadata_objects]
- if expected_origin not in origins:
+
+ # Filter out objects that were clearly not created by this deposit (ie. created
+ # before the deposit started, or that are from unrelated origins)
+ relevant_metadata_objects = [
+ d
+ for d in metadata_objects
+ if d.get("origin") == expected_origin
+ and datetime.datetime.fromisoformat(d["discovery_date"]) >= start_datetime
+ ]
+ if not relevant_metadata_objects:
self.print_result(
"CRITICAL",
- f"Deposited metadata on {swhid} with origin {expected_origin}, "
- f"missing from the list of origins: {origins!r}",
+ f"No recent metadata on {swhid} with origin {expected_origin} in: "
+ f"{metadata_objects!r}",
**metrics,
)
return 2
diff --git a/swh/icinga_plugins/tests/test_deposit.py b/swh/icinga_plugins/tests/test_deposit.py
--- a/swh/icinga_plugins/tests/test_deposit.py
+++ b/swh/icinga_plugins/tests/test_deposit.py
@@ -214,7 +214,13 @@
"get",
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/"
f"?authority=deposit_client%20http://icinga-checker.example.org",
- [{"swhid": swhid, "origin": origin}],
+ [
+ {
+ "swhid": swhid,
+ "origin": origin,
+ "discovery_date": "2999-03-03T10:48:47+00:00",
+ }
+ ],
)
# Then metadata update
@@ -288,7 +294,13 @@
"get",
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/"
f"?authority=deposit_client%20http://icinga-checker.example.org",
- [{"swhid": swhid, "origin": origin}],
+ [
+ {
+ "swhid": swhid,
+ "origin": origin,
+ "discovery_date": "2999-03-03T10:48:47+00:00",
+ }
+ ],
)
# Then metadata update
@@ -360,7 +372,13 @@
"get",
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/"
f"?authority=deposit_client%20http://icinga-checker.example.org",
- [{"swhid": swhid, "origin": origin}],
+ [
+ {
+ "swhid": swhid,
+ "origin": origin,
+ "discovery_date": "2999-03-03T10:48:47+00:00",
+ }
+ ],
)
# Then metadata update calls
@@ -427,7 +445,13 @@
"get",
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/"
f"?authority=deposit_client%20http://icinga-checker.example.org",
- [{"swhid": swhid, "origin": origin}],
+ [
+ {
+ "swhid": swhid,
+ "origin": origin,
+ "discovery_date": "2999-03-03T10:48:47+00:00",
+ }
+ ],
)
scenario.install_mock(requests_mock)
@@ -485,7 +509,13 @@
"get",
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/"
f"?authority=deposit_client%20http://icinga-checker.example.org",
- [{"swhid": swhid, "origin": origin}],
+ [
+ {
+ "swhid": swhid,
+ "origin": origin,
+ "discovery_date": "2999-03-03T10:48:47+00:00",
+ }
+ ],
)
scenario.install_mock(requests_mock)
@@ -585,11 +615,25 @@
)
# Then the checker checks the metadata appeared on the website
+ metadata_list = [
+ {
+ # Filtered out, because wrong origin
+ "swhid": swhid,
+ "origin": "http://wrong-origin.example.org",
+ "discovery_date": "2999-03-03T10:48:47+00:00",
+ },
+ {
+ # Filtered out, because too old
+ "swhid": swhid,
+ "origin": origin,
+ "discovery_date": "2022-03-03T09:48:47+00:00",
+ },
+ ]
scenario.add_step(
"get",
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/"
f"?authority=deposit_client%20http://icinga-checker.example.org",
- [{"swhid": swhid, "origin": "http://wrong-origin.example.org"}],
+ metadata_list,
)
scenario.install_mock(requests_mock)
@@ -608,8 +652,8 @@
)
assert result.output == (
- f"DEPOSIT CRITICAL - Deposited metadata on {swhid} with origin {origin}, "
- f"missing from the list of origins: ['http://wrong-origin.example.org']\n"
+ f"DEPOSIT CRITICAL - No recent metadata on {swhid} with origin {origin} in: "
+ f"{metadata_list!r}\n"
"| 'load_time' = 10.00s\n"
"| 'total_time' = 20.00s\n"
"| 'upload_time' = 0.00s\n"

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 3, 12:59 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3215713

Event Timeline