Implement private Q2 signal contract and durable reference receiver
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a06ecb-456a-71c2-b41e-0755d336e883
This commit is contained in:
parent
31884baf4e
commit
cecef79f31
14 changed files with 655 additions and 20 deletions
44
scripts/platform_event.py
Normal file
44
scripts/platform_event.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Translate S3-owned state classifications without redefining their meaning."""
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from receiver import read_json, instant, STATES
|
||||
|
||||
|
||||
def translate(report, contract):
|
||||
if (set(report) != {'schema', 'cluster_uid', 'evaluated_at', 'signals', 'transport',
|
||||
'guarantees', 'threshold_status', 'healthy'}
|
||||
or report['schema'] != 'railiance-platform.assurance-signal.v1'
|
||||
or report['cluster_uid'] != 'a553c742-0115-43d4-99a4-a5ca56fe0786'
|
||||
or report['transport'] != 'unmonitored'
|
||||
or report['guarantees'] != 'unsupported'
|
||||
or report['threshold_status'] != 'local-diagnostic-only'
|
||||
or set(report['signals']) != set(contract['signals'])):
|
||||
raise ValueError('unexpected platform report')
|
||||
instant(report['evaluated_at'])
|
||||
states = {}
|
||||
for name, value in report['signals'].items():
|
||||
if (set(value) != {'state', 'owner'} or value['state'] not in STATES
|
||||
or value['owner'] not in ('railiance-platform', 'rapp-postgres')):
|
||||
raise ValueError('unexpected signal')
|
||||
states[name] = value['state']
|
||||
if type(report['healthy']) is not bool or report['healthy'] != all(s == 'healthy' for s in states.values()):
|
||||
raise ValueError('inconsistent summary')
|
||||
return dict(schema='railiance-telemetry.signal.v1', id=str(uuid.uuid4()),
|
||||
stream=contract['stream'], producer=contract['producer'],
|
||||
observed_at=report['evaluated_at'], states=states)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument('--contract', required=True, type=Path)
|
||||
p.add_argument('report', type=Path)
|
||||
a = p.parse_args()
|
||||
try:
|
||||
print(json.dumps(translate(read_json(a.report), read_json(a.contract))))
|
||||
except (OSError, ValueError, KeyError, TypeError, AttributeError):
|
||||
print(json.dumps({'status': 'rejected', 'error': 'invalid-platform-report'}))
|
||||
sys.exit(2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue