implemented a general diagnostic command, get_runtime_snapshot, for querying live state from the running application. The first implemented section is listeners, but the response container is intentionally generic so observability and module-state sections can be added later without changing the command name again.

This commit is contained in:
Ilgiz Kamelyev 2026-04-25 21:31:45 +05:00
parent 88d7c5ab48
commit 7ec1bb59b4
27 changed files with 882 additions and 29 deletions

View File

@ -45,3 +45,6 @@ command_executors:
# D-Bus executor is enabled by default.
dbus:
enabled: true
# Runtime snapshot executor exposes live application diagnostics.
runtime_snapshot:
enabled: true

View File

@ -25,7 +25,7 @@ _sym_db = _symbol_database.Default()
import common_pb2 as common__pb2
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0e\x63ommands.proto\x12\x10wfagent.proto.v1\x1a\x0c\x63ommon.proto\"\x9a\x01\n\x0f\x43ommandArgument\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x16\n\x0cstring_value\x18\x02 \x01(\tH\x00\x12\x13\n\tint_value\x18\x03 \x01(\x03H\x00\x12\x16\n\x0c\x64ouble_value\x18\x04 \x01(\x01H\x00\x12\x14\n\nbool_value\x18\x05 \x01(\x08H\x00\x12\x15\n\x0b\x62ytes_value\x18\x06 \x01(\x0cH\x00\x42\x07\n\x05value\"H\n\x15\x43ommandRequestPayload\x12/\n\x04\x61rgs\x18\x01 \x03(\x0b\x32!.wfagent.proto.v1.CommandArgument\"\xb0\x01\n\x16\x43ommandRequestEnvelope\x12$\n\x04meta\x18\x01 \x01(\x0b\x32\x16.wfagent.proto.v1.Meta\x12\x36\n\x06header\x18\x02 \x01(\x0b\x32&.wfagent.proto.v1.CommandRequestHeader\x12\x38\n\x07payload\x18\x03 \x01(\x0b\x32\'.wfagent.proto.v1.CommandRequestPayload\"\xe0\x01\n\x14\x43ommandRequestHeader\x12\x14\n\x0c\x63ommand_kind\x18\x01 \x01(\t\x12\x13\n\x0btarget_type\x18\x02 \x01(\t\x12\x11\n\ttarget_id\x18\x03 \x01(\t\x12\x13\n\x0bissuer_type\x18\x04 \x01(\t\x12\x11\n\tissuer_id\x18\x05 \x01(\t\x12\x10\n\x08priority\x18\x06 \x01(\x05\x12\x1a\n\x12not_before_unix_ms\x18\x07 \x01(\x03\x12\x1a\n\x12\x65xpires_at_unix_ms\x18\x08 \x01(\x03\x12\x18\n\x10\x65xpects_response\x18\t \x01(\x08\"\xad\x01\n\x15\x43ommandResultEnvelope\x12$\n\x04meta\x18\x01 \x01(\x0b\x32\x16.wfagent.proto.v1.Meta\x12\x35\n\x06header\x18\x02 \x01(\x0b\x32%.wfagent.proto.v1.CommandResultHeader\x12\x37\n\x07payload\x18\x03 \x01(\x0b\x32&.wfagent.proto.v1.CommandResultPayload\"\xdb\x01\n\x13\x43ommandResultHeader\x12\x14\n\x0c\x63ommand_kind\x18\x01 \x01(\t\x12\x15\n\rexecutor_type\x18\x02 \x01(\t\x12\x13\n\x0b\x65xecutor_id\x18\x03 \x01(\t\x12\x13\n\x0btarget_type\x18\x04 \x01(\t\x12\x11\n\ttarget_id\x18\x05 \x01(\t\x12\x0e\n\x06status\x18\x06 \x01(\t\x12\x1a\n\x12started_at_unix_ms\x18\x07 \x01(\x03\x12\x1b\n\x13\x66inished_at_unix_ms\x18\x08 \x01(\x03\x12\x11\n\texit_code\x18\t \x01(\x05\"\xd9\x01\n\x14\x43ommandResultPayload\x12\x0e\n\x04text\x18\x01 \x01(\tH\x00\x12\x13\n\traw_bytes\x18\x02 \x01(\x0cH\x00\x12,\n\x02kv\x18\x03 \x01(\x0b\x32\x1e.wfagent.proto.v1.KeyValueListH\x00\x12\x38\n\nstructured\x18\x04 \x01(\x0b\x32\".wfagent.proto.v1.StructuredFieldsH\x00\x12,\n\x05\x65rror\x18\x05 \x01(\x0b\x32\x1b.wfagent.proto.v1.ErrorInfoH\x00\x42\x06\n\x04\x62ody\"\xbc\x02\n\x16\x43ommandExecutionPolicy\x12\x10\n\x08priority\x18\x01 \x01(\x05\x12\x1a\n\x12not_before_unix_ms\x18\x02 \x01(\x03\x12\x1a\n\x12\x65xpires_at_unix_ms\x18\x03 \x01(\x03\x12\x14\n\x0cmax_attempts\x18\x04 \x01(\x05\x12\x14\n\x0cretry_policy\x18\x05 \x01(\t\x12\x18\n\x10retry_backoff_ms\x18\x06 \x01(\x03\x12\x12\n\ntimeout_ms\x18\x07 \x01(\x03\x12\x19\n\x11\x64\x65\x64uplication_key\x18\x08 \x01(\t\x12\x17\n\x0ftarget_lock_key\x18\t \x01(\t\x12\x19\n\x11\x63oncurrency_group\x18\n \x01(\t\x12\x16\n\x0e\x66\x61ilure_policy\x18\x0b \x01(\t\x12\x17\n\x0fqueueing_policy\x18\x0c \x01(\t\"\xbd\x02\n\x15\x43ommandSpoolItemState\x12\x13\n\x0bspool_state\x18\x01 \x01(\t\x12\x15\n\rattempt_count\x18\x02 \x01(\x05\x12\x19\n\x11queued_at_unix_ms\x18\x03 \x01(\x03\x12\x1f\n\x17last_started_at_unix_ms\x18\x04 \x01(\x03\x12 \n\x18last_finished_at_unix_ms\x18\x05 \x01(\x03\x12\x1f\n\x17next_attempt_at_unix_ms\x18\x06 \x01(\x03\x12\x1e\n\x16\x61ssigned_executor_type\x18\x07 \x01(\t\x12 \n\x18\x65xecutor_candidate_types\x18\x08 \x03(\t\x12\x19\n\x11last_failure_code\x18\t \x01(\t\x12\x1c\n\x14last_failure_message\x18\n \x01(\t\"\xe5\x01\n\x10\x43ommandSpoolItem\x12$\n\x04meta\x18\x01 \x01(\x0b\x32\x16.wfagent.proto.v1.Meta\x12\x39\n\x07request\x18\x02 \x01(\x0b\x32(.wfagent.proto.v1.CommandRequestEnvelope\x12\x38\n\x06policy\x18\x03 \x01(\x0b\x32(.wfagent.proto.v1.CommandExecutionPolicy\x12\x36\n\x05state\x18\x04 \x01(\x0b\x32\'.wfagent.proto.v1.CommandSpoolItemState\"\xd4\x01\n\x0f\x43ronCommandSpec\x12\x0f\n\x07\x63ron_id\x18\x01 \x01(\t\x12\x15\n\rschedule_expr\x18\x02 \x01(\t\x12:\n\x08template\x18\x03 \x01(\x0b\x32(.wfagent.proto.v1.CommandRequestEnvelope\x12\x0f\n\x07\x65nabled\x18\x04 \x01(\x08\x12\x16\n\x0emisfire_policy\x18\x05 \x01(\t\x12\x18\n\x10\x64\x65\x66\x61ult_priority\x18\x06 \x01(\x05\x12\x1a\n\x12\x64\x65\x66\x61ult_timeout_ms\x18\x07 \x01(\x03\x62\x06proto3')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0e\x63ommands.proto\x12\x10wfagent.proto.v1\x1a\x0c\x63ommon.proto\"\x9a\x01\n\x0f\x43ommandArgument\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x16\n\x0cstring_value\x18\x02 \x01(\tH\x00\x12\x13\n\tint_value\x18\x03 \x01(\x03H\x00\x12\x16\n\x0c\x64ouble_value\x18\x04 \x01(\x01H\x00\x12\x14\n\nbool_value\x18\x05 \x01(\x08H\x00\x12\x15\n\x0b\x62ytes_value\x18\x06 \x01(\x0cH\x00\x42\x07\n\x05value\"H\n\x15\x43ommandRequestPayload\x12/\n\x04\x61rgs\x18\x01 \x03(\x0b\x32!.wfagent.proto.v1.CommandArgument\"\xb0\x01\n\x16\x43ommandRequestEnvelope\x12$\n\x04meta\x18\x01 \x01(\x0b\x32\x16.wfagent.proto.v1.Meta\x12\x36\n\x06header\x18\x02 \x01(\x0b\x32&.wfagent.proto.v1.CommandRequestHeader\x12\x38\n\x07payload\x18\x03 \x01(\x0b\x32\'.wfagent.proto.v1.CommandRequestPayload\"\xe0\x01\n\x14\x43ommandRequestHeader\x12\x14\n\x0c\x63ommand_kind\x18\x01 \x01(\t\x12\x13\n\x0btarget_type\x18\x02 \x01(\t\x12\x11\n\ttarget_id\x18\x03 \x01(\t\x12\x13\n\x0bissuer_type\x18\x04 \x01(\t\x12\x11\n\tissuer_id\x18\x05 \x01(\t\x12\x10\n\x08priority\x18\x06 \x01(\x05\x12\x1a\n\x12not_before_unix_ms\x18\x07 \x01(\x03\x12\x1a\n\x12\x65xpires_at_unix_ms\x18\x08 \x01(\x03\x12\x18\n\x10\x65xpects_response\x18\t \x01(\x08\"\xad\x01\n\x15\x43ommandResultEnvelope\x12$\n\x04meta\x18\x01 \x01(\x0b\x32\x16.wfagent.proto.v1.Meta\x12\x35\n\x06header\x18\x02 \x01(\x0b\x32%.wfagent.proto.v1.CommandResultHeader\x12\x37\n\x07payload\x18\x03 \x01(\x0b\x32&.wfagent.proto.v1.CommandResultPayload\"I\n\x0cListenerInfo\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04type\x18\x02 \x01(\t\x12\x0e\n\x06\x65nable\x18\x03 \x01(\x08\x12\r\n\x05state\x18\x04 \x01(\t\"D\n\x0fRuntimeSnapshot\x12\x31\n\tlisteners\x18\x01 \x03(\x0b\x32\x1e.wfagent.proto.v1.ListenerInfo\"\xdb\x01\n\x13\x43ommandResultHeader\x12\x14\n\x0c\x63ommand_kind\x18\x01 \x01(\t\x12\x15\n\rexecutor_type\x18\x02 \x01(\t\x12\x13\n\x0b\x65xecutor_id\x18\x03 \x01(\t\x12\x13\n\x0btarget_type\x18\x04 \x01(\t\x12\x11\n\ttarget_id\x18\x05 \x01(\t\x12\x0e\n\x06status\x18\x06 \x01(\t\x12\x1a\n\x12started_at_unix_ms\x18\x07 \x01(\x03\x12\x1b\n\x13\x66inished_at_unix_ms\x18\x08 \x01(\x03\x12\x11\n\texit_code\x18\t \x01(\x05\"\x98\x02\n\x14\x43ommandResultPayload\x12\x0e\n\x04text\x18\x01 \x01(\tH\x00\x12\x13\n\traw_bytes\x18\x02 \x01(\x0cH\x00\x12,\n\x02kv\x18\x03 \x01(\x0b\x32\x1e.wfagent.proto.v1.KeyValueListH\x00\x12\x38\n\nstructured\x18\x04 \x01(\x0b\x32\".wfagent.proto.v1.StructuredFieldsH\x00\x12,\n\x05\x65rror\x18\x05 \x01(\x0b\x32\x1b.wfagent.proto.v1.ErrorInfoH\x00\x12=\n\x10runtime_snapshot\x18\x06 \x01(\x0b\x32!.wfagent.proto.v1.RuntimeSnapshotH\x00\x42\x06\n\x04\x62ody\"\xbc\x02\n\x16\x43ommandExecutionPolicy\x12\x10\n\x08priority\x18\x01 \x01(\x05\x12\x1a\n\x12not_before_unix_ms\x18\x02 \x01(\x03\x12\x1a\n\x12\x65xpires_at_unix_ms\x18\x03 \x01(\x03\x12\x14\n\x0cmax_attempts\x18\x04 \x01(\x05\x12\x14\n\x0cretry_policy\x18\x05 \x01(\t\x12\x18\n\x10retry_backoff_ms\x18\x06 \x01(\x03\x12\x12\n\ntimeout_ms\x18\x07 \x01(\x03\x12\x19\n\x11\x64\x65\x64uplication_key\x18\x08 \x01(\t\x12\x17\n\x0ftarget_lock_key\x18\t \x01(\t\x12\x19\n\x11\x63oncurrency_group\x18\n \x01(\t\x12\x16\n\x0e\x66\x61ilure_policy\x18\x0b \x01(\t\x12\x17\n\x0fqueueing_policy\x18\x0c \x01(\t\"\xbd\x02\n\x15\x43ommandSpoolItemState\x12\x13\n\x0bspool_state\x18\x01 \x01(\t\x12\x15\n\rattempt_count\x18\x02 \x01(\x05\x12\x19\n\x11queued_at_unix_ms\x18\x03 \x01(\x03\x12\x1f\n\x17last_started_at_unix_ms\x18\x04 \x01(\x03\x12 \n\x18last_finished_at_unix_ms\x18\x05 \x01(\x03\x12\x1f\n\x17next_attempt_at_unix_ms\x18\x06 \x01(\x03\x12\x1e\n\x16\x61ssigned_executor_type\x18\x07 \x01(\t\x12 \n\x18\x65xecutor_candidate_types\x18\x08 \x03(\t\x12\x19\n\x11last_failure_code\x18\t \x01(\t\x12\x1c\n\x14last_failure_message\x18\n \x01(\t\"\xe5\x01\n\x10\x43ommandSpoolItem\x12$\n\x04meta\x18\x01 \x01(\x0b\x32\x16.wfagent.proto.v1.Meta\x12\x39\n\x07request\x18\x02 \x01(\x0b\x32(.wfagent.proto.v1.CommandRequestEnvelope\x12\x38\n\x06policy\x18\x03 \x01(\x0b\x32(.wfagent.proto.v1.CommandExecutionPolicy\x12\x36\n\x05state\x18\x04 \x01(\x0b\x32\'.wfagent.proto.v1.CommandSpoolItemState\"\xd4\x01\n\x0f\x43ronCommandSpec\x12\x0f\n\x07\x63ron_id\x18\x01 \x01(\t\x12\x15\n\rschedule_expr\x18\x02 \x01(\t\x12:\n\x08template\x18\x03 \x01(\x0b\x32(.wfagent.proto.v1.CommandRequestEnvelope\x12\x0f\n\x07\x65nabled\x18\x04 \x01(\x08\x12\x16\n\x0emisfire_policy\x18\x05 \x01(\t\x12\x18\n\x10\x64\x65\x66\x61ult_priority\x18\x06 \x01(\x05\x12\x1a\n\x12\x64\x65\x66\x61ult_timeout_ms\x18\x07 \x01(\x03\x62\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
@ -42,16 +42,20 @@ if not _descriptor._USE_C_DESCRIPTORS:
_globals['_COMMANDREQUESTHEADER']._serialized_end=685
_globals['_COMMANDRESULTENVELOPE']._serialized_start=688
_globals['_COMMANDRESULTENVELOPE']._serialized_end=861
_globals['_COMMANDRESULTHEADER']._serialized_start=864
_globals['_COMMANDRESULTHEADER']._serialized_end=1083
_globals['_COMMANDRESULTPAYLOAD']._serialized_start=1086
_globals['_COMMANDRESULTPAYLOAD']._serialized_end=1303
_globals['_COMMANDEXECUTIONPOLICY']._serialized_start=1306
_globals['_COMMANDEXECUTIONPOLICY']._serialized_end=1622
_globals['_COMMANDSPOOLITEMSTATE']._serialized_start=1625
_globals['_COMMANDSPOOLITEMSTATE']._serialized_end=1942
_globals['_COMMANDSPOOLITEM']._serialized_start=1945
_globals['_COMMANDSPOOLITEM']._serialized_end=2174
_globals['_CRONCOMMANDSPEC']._serialized_start=2177
_globals['_CRONCOMMANDSPEC']._serialized_end=2389
_globals['_LISTENERINFO']._serialized_start=863
_globals['_LISTENERINFO']._serialized_end=936
_globals['_RUNTIMESNAPSHOT']._serialized_start=938
_globals['_RUNTIMESNAPSHOT']._serialized_end=1006
_globals['_COMMANDRESULTHEADER']._serialized_start=1009
_globals['_COMMANDRESULTHEADER']._serialized_end=1228
_globals['_COMMANDRESULTPAYLOAD']._serialized_start=1231
_globals['_COMMANDRESULTPAYLOAD']._serialized_end=1511
_globals['_COMMANDEXECUTIONPOLICY']._serialized_start=1514
_globals['_COMMANDEXECUTIONPOLICY']._serialized_end=1830
_globals['_COMMANDSPOOLITEMSTATE']._serialized_start=1833
_globals['_COMMANDSPOOLITEMSTATE']._serialized_end=2150
_globals['_COMMANDSPOOLITEM']._serialized_start=2153
_globals['_COMMANDSPOOLITEM']._serialized_end=2382
_globals['_CRONCOMMANDSPEC']._serialized_start=2385
_globals['_CRONCOMMANDSPEC']._serialized_end=2597
# @@protoc_insertion_point(module_scope)

View File

@ -26,7 +26,7 @@ import common_pb2 as common__pb2
import commands_pb2 as commands__pb2
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10northbound.proto\x12\x15wfagent.northbound.v1\x1a\x0c\x63ommon.proto\x1a\x0e\x63ommands.proto\"\x9a\x04\n\x0e\x43lientEnvelope\x12\x18\n\x10protocol_version\x18\x01 \x01(\t\x12\x14\n\x0cmessage_kind\x18\x02 \x01(\t\x12\x12\n\nsession_id\x18\x03 \x01(\t\x12\x12\n\nrequest_id\x18\x04 \x01(\t\x12\x16\n\x0e\x63orrelation_id\x18\x05 \x01(\t\x12\x17\n\x0fsent_at_unix_ms\x18\x06 \x01(\x03\x12:\n\x0c\x63lient_hello\x18\n \x01(\x0b\x32\".wfagent.northbound.v1.ClientHelloH\x00\x12G\n\x0f\x63ommand_request\x18\x0b \x01(\x0b\x32,.wfagent.northbound.v1.CommandRequestMessageH\x00\x12\x45\n\x0e\x63ommand_cancel\x18\x0c \x01(\x0b\x32+.wfagent.northbound.v1.CommandCancelMessageH\x00\x12<\n\tsubscribe\x18\r \x01(\x0b\x32\'.wfagent.northbound.v1.SubscribeRequestH\x00\x12@\n\x0bunsubscribe\x18\x0e \x01(\x0b\x32).wfagent.northbound.v1.UnsubscribeRequestH\x00\x12+\n\x04ping\x18\x0f \x01(\x0b\x32\x1b.wfagent.northbound.v1.PingH\x00\x42\x06\n\x04\x62ody\"\x86\x04\n\x0eServerEnvelope\x12\x18\n\x10protocol_version\x18\x01 \x01(\t\x12\x14\n\x0cmessage_kind\x18\x02 \x01(\t\x12\x12\n\nsession_id\x18\x03 \x01(\t\x12\x12\n\nrequest_id\x18\x04 \x01(\t\x12\x16\n\x0e\x63orrelation_id\x18\x05 \x01(\t\x12\x17\n\x0fsent_at_unix_ms\x18\x06 \x01(\x03\x12:\n\x0cserver_hello\x18\n \x01(\x0b\x32\".wfagent.northbound.v1.ServerHelloH\x00\x12I\n\x10\x63ommand_response\x18\x0b \x01(\x0b\x32-.wfagent.northbound.v1.CommandResponseMessageH\x00\x12\x34\n\x05\x65vent\x18\x0c \x01(\x0b\x32#.wfagent.northbound.v1.EventMessageH\x00\x12\x35\n\x05\x65rror\x18\r \x01(\x0b\x32$.wfagent.northbound.v1.ErrorResponseH\x00\x12+\n\x04pong\x18\x0e \x01(\x0b\x32\x1b.wfagent.northbound.v1.PongH\x00\x12\x42\n\rsession_state\x18\x0f \x01(\x0b\x32).wfagent.northbound.v1.SessionStateUpdateH\x00\x42\x06\n\x04\x62ody\":\n\x0b\x43lientHello\x12\x13\n\x0b\x63lient_type\x18\x01 \x01(\t\x12\x16\n\x0e\x63lient_version\x18\x02 \x01(\t\"T\n\x0bServerHello\x12\x13\n\x0bserver_name\x18\x01 \x01(\t\x12\x18\n\x10protocol_version\x18\x02 \x01(\t\x12\x16\n\x0eserver_version\x18\x03 \x01(\t\"\xfc\x01\n\x15\x43ommandRequestMessage\x12\x34\n\x06target\x18\x01 \x01(\x0b\x32$.wfagent.northbound.v1.CommandTarget\x12\x39\n\x07\x63ommand\x18\x02 \x01(\x0b\x32(.wfagent.northbound.v1.CommandDescriptor\x12\x34\n\targuments\x18\x03 \x03(\x0b\x32!.wfagent.proto.v1.CommandArgument\x12<\n\x07options\x18\x04 \x01(\x0b\x32+.wfagent.northbound.v1.CommandClientOptions\"M\n\rCommandTarget\x12\x13\n\x0btarget_type\x18\x01 \x01(\t\x12\x11\n\ttarget_id\x18\x02 \x01(\t\x12\x14\n\x0ctarget_scope\x18\x03 \x01(\t\"?\n\x11\x43ommandDescriptor\x12\x14\n\x0c\x63ommand_kind\x18\x01 \x01(\t\x12\x14\n\x0c\x63ommand_name\x18\x02 \x01(\t\"\x88\x01\n\x14\x43ommandClientOptions\x12\x18\n\x10\x65xpects_response\x18\x01 \x01(\x08\x12\x12\n\ntimeout_ms\x18\x02 \x01(\x03\x12\x15\n\rpriority_hint\x18\x03 \x01(\x05\x12\x16\n\x0e\x61llow_queueing\x18\x04 \x01(\x08\x12\x13\n\x0b\x61llow_retry\x18\x05 \x01(\x08\"A\n\x14\x43ommandCancelMessage\x12\x19\n\x11target_request_id\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\"\xcf\x02\n\x16\x43ommandResponseMessage\x12\x0e\n\x06status\x18\x01 \x01(\t\x12\x14\n\x0c\x63ommand_kind\x18\x02 \x01(\t\x12\x13\n\x0btarget_type\x18\x03 \x01(\t\x12\x11\n\ttarget_id\x18\x04 \x01(\t\x12\x1a\n\x12started_at_unix_ms\x18\x05 \x01(\x03\x12\x1b\n\x13\x66inished_at_unix_ms\x18\x06 \x01(\x03\x12\x0e\n\x04text\x18\n \x01(\tH\x00\x12,\n\x02kv\x18\x0b \x01(\x0b\x32\x1e.wfagent.proto.v1.KeyValueListH\x00\x12\x38\n\nstructured\x18\x0c \x01(\x0b\x32\".wfagent.proto.v1.StructuredFieldsH\x00\x12,\n\x05\x65rror\x18\r \x01(\x0b\x32\x1b.wfagent.proto.v1.ErrorInfoH\x00\x42\x08\n\x06result\"\xfc\x01\n\x0c\x45ventMessage\x12\x12\n\nevent_type\x18\x01 \x01(\t\x12\x13\n\x0bsource_type\x18\x02 \x01(\t\x12\x11\n\tsource_id\x18\x03 \x01(\t\x12\x10\n\x08severity\x18\x04 \x01(\t\x12\x1b\n\x13observed_at_unix_ms\x18\x05 \x01(\x03\x12\x0e\n\x04text\x18\n \x01(\tH\x00\x12,\n\x02kv\x18\x0b \x01(\x0b\x32\x1e.wfagent.proto.v1.KeyValueListH\x00\x12\x38\n\nstructured\x18\x0c \x01(\x0b\x32\".wfagent.proto.v1.StructuredFieldsH\x00\x42\t\n\x07payload\"\x88\x01\n\x10SubscribeRequest\x12\x17\n\x0fsubscription_id\x18\x01 \x01(\t\x12\x12\n\nevent_type\x18\x02 \x01(\t\x12\x13\n\x0bsource_type\x18\x03 \x01(\t\x12\x11\n\tsource_id\x18\x04 \x01(\t\x12\r\n\x05topic\x18\x05 \x01(\t\x12\x10\n\x08severity\x18\x06 \x01(\t\"-\n\x12UnsubscribeRequest\x12\x17\n\x0fsubscription_id\x18\x01 \x01(\t\"K\n\rErrorResponse\x12\x12\n\nerror_code\x18\x01 \x01(\t\x12\x15\n\rerror_message\x18\x02 \x01(\t\x12\x0f\n\x07\x64\x65tails\x18\x03 \x01(\t\";\n\x12SessionStateUpdate\x12\x15\n\rsession_state\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\"\x06\n\x04Ping\"\x06\n\x04Pongb\x06proto3')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10northbound.proto\x12\x15wfagent.northbound.v1\x1a\x0c\x63ommon.proto\x1a\x0e\x63ommands.proto\"\x9a\x04\n\x0e\x43lientEnvelope\x12\x18\n\x10protocol_version\x18\x01 \x01(\t\x12\x14\n\x0cmessage_kind\x18\x02 \x01(\t\x12\x12\n\nsession_id\x18\x03 \x01(\t\x12\x12\n\nrequest_id\x18\x04 \x01(\t\x12\x16\n\x0e\x63orrelation_id\x18\x05 \x01(\t\x12\x17\n\x0fsent_at_unix_ms\x18\x06 \x01(\x03\x12:\n\x0c\x63lient_hello\x18\n \x01(\x0b\x32\".wfagent.northbound.v1.ClientHelloH\x00\x12G\n\x0f\x63ommand_request\x18\x0b \x01(\x0b\x32,.wfagent.northbound.v1.CommandRequestMessageH\x00\x12\x45\n\x0e\x63ommand_cancel\x18\x0c \x01(\x0b\x32+.wfagent.northbound.v1.CommandCancelMessageH\x00\x12<\n\tsubscribe\x18\r \x01(\x0b\x32\'.wfagent.northbound.v1.SubscribeRequestH\x00\x12@\n\x0bunsubscribe\x18\x0e \x01(\x0b\x32).wfagent.northbound.v1.UnsubscribeRequestH\x00\x12+\n\x04ping\x18\x0f \x01(\x0b\x32\x1b.wfagent.northbound.v1.PingH\x00\x42\x06\n\x04\x62ody\"\x86\x04\n\x0eServerEnvelope\x12\x18\n\x10protocol_version\x18\x01 \x01(\t\x12\x14\n\x0cmessage_kind\x18\x02 \x01(\t\x12\x12\n\nsession_id\x18\x03 \x01(\t\x12\x12\n\nrequest_id\x18\x04 \x01(\t\x12\x16\n\x0e\x63orrelation_id\x18\x05 \x01(\t\x12\x17\n\x0fsent_at_unix_ms\x18\x06 \x01(\x03\x12:\n\x0cserver_hello\x18\n \x01(\x0b\x32\".wfagent.northbound.v1.ServerHelloH\x00\x12I\n\x10\x63ommand_response\x18\x0b \x01(\x0b\x32-.wfagent.northbound.v1.CommandResponseMessageH\x00\x12\x34\n\x05\x65vent\x18\x0c \x01(\x0b\x32#.wfagent.northbound.v1.EventMessageH\x00\x12\x35\n\x05\x65rror\x18\r \x01(\x0b\x32$.wfagent.northbound.v1.ErrorResponseH\x00\x12+\n\x04pong\x18\x0e \x01(\x0b\x32\x1b.wfagent.northbound.v1.PongH\x00\x12\x42\n\rsession_state\x18\x0f \x01(\x0b\x32).wfagent.northbound.v1.SessionStateUpdateH\x00\x42\x06\n\x04\x62ody\":\n\x0b\x43lientHello\x12\x13\n\x0b\x63lient_type\x18\x01 \x01(\t\x12\x16\n\x0e\x63lient_version\x18\x02 \x01(\t\"T\n\x0bServerHello\x12\x13\n\x0bserver_name\x18\x01 \x01(\t\x12\x18\n\x10protocol_version\x18\x02 \x01(\t\x12\x16\n\x0eserver_version\x18\x03 \x01(\t\"\xfc\x01\n\x15\x43ommandRequestMessage\x12\x34\n\x06target\x18\x01 \x01(\x0b\x32$.wfagent.northbound.v1.CommandTarget\x12\x39\n\x07\x63ommand\x18\x02 \x01(\x0b\x32(.wfagent.northbound.v1.CommandDescriptor\x12\x34\n\targuments\x18\x03 \x03(\x0b\x32!.wfagent.proto.v1.CommandArgument\x12<\n\x07options\x18\x04 \x01(\x0b\x32+.wfagent.northbound.v1.CommandClientOptions\"M\n\rCommandTarget\x12\x13\n\x0btarget_type\x18\x01 \x01(\t\x12\x11\n\ttarget_id\x18\x02 \x01(\t\x12\x14\n\x0ctarget_scope\x18\x03 \x01(\t\"?\n\x11\x43ommandDescriptor\x12\x14\n\x0c\x63ommand_kind\x18\x01 \x01(\t\x12\x14\n\x0c\x63ommand_name\x18\x02 \x01(\t\"\x88\x01\n\x14\x43ommandClientOptions\x12\x18\n\x10\x65xpects_response\x18\x01 \x01(\x08\x12\x12\n\ntimeout_ms\x18\x02 \x01(\x03\x12\x15\n\rpriority_hint\x18\x03 \x01(\x05\x12\x16\n\x0e\x61llow_queueing\x18\x04 \x01(\x08\x12\x13\n\x0b\x61llow_retry\x18\x05 \x01(\x08\"A\n\x14\x43ommandCancelMessage\x12\x19\n\x11target_request_id\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\"\x8e\x03\n\x16\x43ommandResponseMessage\x12\x0e\n\x06status\x18\x01 \x01(\t\x12\x14\n\x0c\x63ommand_kind\x18\x02 \x01(\t\x12\x13\n\x0btarget_type\x18\x03 \x01(\t\x12\x11\n\ttarget_id\x18\x04 \x01(\t\x12\x1a\n\x12started_at_unix_ms\x18\x05 \x01(\x03\x12\x1b\n\x13\x66inished_at_unix_ms\x18\x06 \x01(\x03\x12\x0e\n\x04text\x18\n \x01(\tH\x00\x12,\n\x02kv\x18\x0b \x01(\x0b\x32\x1e.wfagent.proto.v1.KeyValueListH\x00\x12\x38\n\nstructured\x18\x0c \x01(\x0b\x32\".wfagent.proto.v1.StructuredFieldsH\x00\x12,\n\x05\x65rror\x18\r \x01(\x0b\x32\x1b.wfagent.proto.v1.ErrorInfoH\x00\x12=\n\x10runtime_snapshot\x18\x0e \x01(\x0b\x32!.wfagent.proto.v1.RuntimeSnapshotH\x00\x42\x08\n\x06result\"\xfc\x01\n\x0c\x45ventMessage\x12\x12\n\nevent_type\x18\x01 \x01(\t\x12\x13\n\x0bsource_type\x18\x02 \x01(\t\x12\x11\n\tsource_id\x18\x03 \x01(\t\x12\x10\n\x08severity\x18\x04 \x01(\t\x12\x1b\n\x13observed_at_unix_ms\x18\x05 \x01(\x03\x12\x0e\n\x04text\x18\n \x01(\tH\x00\x12,\n\x02kv\x18\x0b \x01(\x0b\x32\x1e.wfagent.proto.v1.KeyValueListH\x00\x12\x38\n\nstructured\x18\x0c \x01(\x0b\x32\".wfagent.proto.v1.StructuredFieldsH\x00\x42\t\n\x07payload\"\x88\x01\n\x10SubscribeRequest\x12\x17\n\x0fsubscription_id\x18\x01 \x01(\t\x12\x12\n\nevent_type\x18\x02 \x01(\t\x12\x13\n\x0bsource_type\x18\x03 \x01(\t\x12\x11\n\tsource_id\x18\x04 \x01(\t\x12\r\n\x05topic\x18\x05 \x01(\t\x12\x10\n\x08severity\x18\x06 \x01(\t\"-\n\x12UnsubscribeRequest\x12\x17\n\x0fsubscription_id\x18\x01 \x01(\t\"K\n\rErrorResponse\x12\x12\n\nerror_code\x18\x01 \x01(\t\x12\x15\n\rerror_message\x18\x02 \x01(\t\x12\x0f\n\x07\x64\x65tails\x18\x03 \x01(\t\";\n\x12SessionStateUpdate\x12\x15\n\rsession_state\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\"\x06\n\x04Ping\"\x06\n\x04Pongb\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
@ -52,19 +52,19 @@ if not _descriptor._USE_C_DESCRIPTORS:
_globals['_COMMANDCANCELMESSAGE']._serialized_start=1819
_globals['_COMMANDCANCELMESSAGE']._serialized_end=1884
_globals['_COMMANDRESPONSEMESSAGE']._serialized_start=1887
_globals['_COMMANDRESPONSEMESSAGE']._serialized_end=2222
_globals['_EVENTMESSAGE']._serialized_start=2225
_globals['_EVENTMESSAGE']._serialized_end=2477
_globals['_SUBSCRIBEREQUEST']._serialized_start=2480
_globals['_SUBSCRIBEREQUEST']._serialized_end=2616
_globals['_UNSUBSCRIBEREQUEST']._serialized_start=2618
_globals['_UNSUBSCRIBEREQUEST']._serialized_end=2663
_globals['_ERRORRESPONSE']._serialized_start=2665
_globals['_ERRORRESPONSE']._serialized_end=2740
_globals['_SESSIONSTATEUPDATE']._serialized_start=2742
_globals['_SESSIONSTATEUPDATE']._serialized_end=2801
_globals['_PING']._serialized_start=2803
_globals['_PING']._serialized_end=2809
_globals['_PONG']._serialized_start=2811
_globals['_PONG']._serialized_end=2817
_globals['_COMMANDRESPONSEMESSAGE']._serialized_end=2285
_globals['_EVENTMESSAGE']._serialized_start=2288
_globals['_EVENTMESSAGE']._serialized_end=2540
_globals['_SUBSCRIBEREQUEST']._serialized_start=2543
_globals['_SUBSCRIBEREQUEST']._serialized_end=2679
_globals['_UNSUBSCRIBEREQUEST']._serialized_start=2681
_globals['_UNSUBSCRIBEREQUEST']._serialized_end=2726
_globals['_ERRORRESPONSE']._serialized_start=2728
_globals['_ERRORRESPONSE']._serialized_end=2803
_globals['_SESSIONSTATEUPDATE']._serialized_start=2805
_globals['_SESSIONSTATEUPDATE']._serialized_end=2864
_globals['_PING']._serialized_start=2866
_globals['_PING']._serialized_end=2872
_globals['_PONG']._serialized_start=2874
_globals['_PONG']._serialized_end=2880
# @@protoc_insertion_point(module_scope)

View File

@ -247,6 +247,7 @@ class CliNorthboundProtocol:
kv: Any | None = None,
structured: Any | None = None,
error: Any | None = None,
runtime_snapshot: Any | None = None,
sent_at_unix_ms: int | None = None,
) -> Any:
response_kwargs: dict[str, Any] = {
@ -265,6 +266,8 @@ class CliNorthboundProtocol:
response_kwargs["structured"] = structured
if error is not None:
response_kwargs["error"] = error
if runtime_snapshot is not None:
response_kwargs["runtime_snapshot"] = runtime_snapshot
return command_northbound_bindings.ServerEnvelope(
protocol_version=self.protocol_version,
message_kind="COMMAND_RESPONSE",

View File

@ -126,6 +126,29 @@ def _format_command_error(error: Any) -> str:
return " ".join(parts).strip()
def _format_runtime_snapshot(payload: Any) -> str:
runtime_snapshot = payload
if not hasattr(runtime_snapshot, "listeners"):
runtime_snapshot = getattr(payload, "runtime_snapshot", None)
if runtime_snapshot is None:
return "runtime snapshot <missing>"
listeners = getattr(runtime_snapshot, "listeners", ())
if not listeners:
return "runtime snapshot listeners=[]"
rendered_listeners: list[str] = []
for listener in listeners:
name = str(getattr(listener, "name", "") or "")
listener_type = str(getattr(listener, "type", "") or "")
enable = bool(getattr(listener, "enable", False))
state = str(getattr(listener, "state", "") or "")
rendered_listeners.append(
f"name={name} type={listener_type} enable={str(enable).lower()} state={state}"
)
return "runtime snapshot listeners=[" + ", ".join(rendered_listeners) + "]"
def _format_command_response(envelope: Any) -> str:
command_response = getattr(envelope, "command_response", None)
if command_response is None:
@ -165,6 +188,10 @@ def _format_command_response(envelope: Any) -> str:
parts.append(_format_structured_payload(command_response))
elif result_kind == "error":
parts.append(_format_command_error(getattr(command_response, "error", None)))
elif result_kind == "runtime_snapshot":
parts.append(
_format_runtime_snapshot(getattr(command_response, "runtime_snapshot", None))
)
return " ".join(parts)

View File

@ -43,6 +43,7 @@ from app.command.executors import (
BaseCommandExecutor,
CommandArgumentReader,
DbusCommandExecutor,
GetRuntimeSnapshotCommandExecutor,
deadline_from_timeout_ms,
error_from_exception,
remaining_timeout_ms,
@ -104,6 +105,7 @@ __all__ = [
"BaseCommandExecutor",
"CommandArgumentReader",
"DbusCommandExecutor",
"GetRuntimeSnapshotCommandExecutor",
"deadline_from_timeout_ms",
"error_from_exception",
"remaining_timeout_ms",

View File

@ -325,6 +325,7 @@ class CommandBridgeNorthboundCodec:
kv: Any | None = None,
structured: Any | None = None,
error: Any | None = None,
runtime_snapshot: Any | None = None,
sent_at_unix_ms: int | None = None,
) -> Any:
response_kwargs: dict[str, Any] = {
@ -343,6 +344,8 @@ class CommandBridgeNorthboundCodec:
response_kwargs["structured"] = structured
if error is not None:
response_kwargs["error"] = error
if runtime_snapshot is not None:
response_kwargs["runtime_snapshot"] = runtime_snapshot
return command_northbound_bindings.ServerEnvelope(
protocol_version=self.protocol_version,
message_kind="COMMAND_RESPONSE",

View File

@ -7,6 +7,9 @@ from app.command.executors.base import (
result_factory,
)
from app.command.executors.dbus_executor import DbusCommandExecutor
from app.command.executors.runtime_snapshot import (
GetRuntimeSnapshotCommandExecutor,
)
__all__ = [
"BaseCommandExecutor",
@ -16,4 +19,5 @@ __all__ = [
"remaining_timeout_ms",
"result_factory",
"DbusCommandExecutor",
"GetRuntimeSnapshotCommandExecutor",
]

View File

@ -197,6 +197,7 @@ def result_factory(
kv: Any | None = None,
structured: Any | None = None,
error: Any | None = None,
runtime_snapshot: Any | None = None,
message_id: str = "",
correlation_id: str = "",
) -> Any:
@ -225,6 +226,8 @@ def result_factory(
payload_kwargs["structured"] = structured
if error is not None:
payload_kwargs["error"] = _error_info(error)
if runtime_snapshot is not None:
payload_kwargs["runtime_snapshot"] = runtime_snapshot
return command_bindings.CommandResultEnvelope(
meta=response_meta,
header=command_bindings.CommandResultHeader(
@ -340,6 +343,7 @@ class BaseCommandExecutor(ABC):
kv: Any | None = None,
structured: Any | None = None,
error: Any | None = None,
runtime_snapshot: Any | None = None,
message_id: str = "",
correlation_id: str = "",
) -> Any:
@ -356,6 +360,7 @@ class BaseCommandExecutor(ABC):
kv=kv,
structured=structured,
error=error,
runtime_snapshot=runtime_snapshot,
message_id=message_id,
correlation_id=correlation_id,
)

View File

@ -0,0 +1,73 @@
from __future__ import annotations
from time import time_ns
from typing import Any
from app.command.executors.base import BaseCommandExecutor, error_from_exception
from app.shared.contracts.proto.v1 import command_bindings
def _now_ms() -> int:
return time_ns() // 1_000_000
class GetRuntimeSnapshotCommandExecutor(BaseCommandExecutor):
supported_command_kinds = ("get_runtime_snapshot",)
def __init__(
self,
*,
snapshot_provider: Any | None = None,
name: str = "runtime-snapshot-executor",
executor_type: str | None = None,
) -> None:
super().__init__(name=name, executor_type=executor_type or "runtime_snapshot")
self._snapshot_provider = snapshot_provider
def can_execute(self, request: Any, context: Any) -> bool:
_ = context
command_kind = str(
getattr(getattr(request, "header", None), "command_kind", "") or ""
).lower()
return command_kind == "get_runtime_snapshot" or super().can_execute(
request, context
)
def execute(self, request: Any, context: Any) -> Any:
_ = context
self.mark_received(request)
started_at = _now_ms()
self.mark_executed(request)
try:
snapshot = self._snapshot()
result = self.result_factory(
request,
status="SUCCEEDED",
started_at_unix_ms=started_at,
finished_at_unix_ms=_now_ms(),
exit_code=0,
runtime_snapshot=snapshot,
)
self.mark_succeeded(request)
return result
except Exception as exc:
command_error = error_from_exception(exc)
self.mark_failed(request, command_error)
return self.result_factory(
request,
status="FAILED",
started_at_unix_ms=started_at,
finished_at_unix_ms=_now_ms(),
exit_code=1,
error=command_error,
)
def _snapshot(self) -> command_bindings.RuntimeSnapshot:
provider = self._snapshot_provider
if provider is None:
return command_bindings.RuntimeSnapshot()
snapshot = provider.snapshot()
if isinstance(snapshot, command_bindings.RuntimeSnapshot):
return snapshot
listeners = getattr(snapshot, "listeners", ())
return command_bindings.RuntimeSnapshot(listeners=list(listeners))

View File

@ -15,6 +15,7 @@ import yaml
from app.command import (
CommandExecutor,
CommandObservabilityService,
GetRuntimeSnapshotCommandExecutor,
build_command_runtime,
build_command_runtime_orchestrator,
load_command_runtime_settings,
@ -31,6 +32,7 @@ from app.event import (
load_event_runtime_settings,
)
from app.runtime.config.loader import load_runtime_config
from app.runtime.snapshot import RuntimeSnapshotService
from app.shared.logging import configure_logging
from app.shared.dbus import DbusConnectionAdapter
from app.shared.contracts.proto.v1 import command_bindings
@ -421,6 +423,15 @@ def run_backend_service(
if command_enabled
else {}
)
runtime_snapshot_service = (
RuntimeSnapshotService(event_runtime) if command_enabled else None
)
if command_enabled:
command_executor_factories["runtime_snapshot"] = (
lambda snapshot_provider=runtime_snapshot_service: GetRuntimeSnapshotCommandExecutor(
snapshot_provider=snapshot_provider
)
)
command_cron_specs = (
_build_command_cron_specs(config_source, config) if command_enabled else []
)

1
src/app/runtime/__init__.py Executable file → Normal file
View File

@ -0,0 +1 @@
"""Runtime package."""

View File

@ -0,0 +1,5 @@
from app.runtime.snapshot.service import RuntimeSnapshotService
__all__ = [
"RuntimeSnapshotService",
]

View File

@ -0,0 +1,62 @@
from __future__ import annotations
from typing import Any
from app.event.contracts.status import EventLifecycleState
from app.event.runtime.wiring import EventRuntime
from app.shared.contracts.proto.v1 import command_bindings
def _enum_text(value: Any) -> str:
if value is None:
return ""
return str(getattr(value, "value", value) or "")
def _default_listener_type(listener: Any) -> str:
name = str(getattr(listener, "__class__", type(listener)).__name__ or "")
if name.endswith("EventListener"):
name = name.removesuffix("EventListener")
return name.lower()
class RuntimeSnapshotService:
def __init__(self, event_runtime: EventRuntime | None = None) -> None:
self._event_runtime = event_runtime
@property
def event_runtime(self) -> EventRuntime | None:
return self._event_runtime
def snapshot(self) -> command_bindings.RuntimeSnapshot:
listeners: list[Any] = []
runtime = self._event_runtime
if runtime is not None:
for binding in runtime.listener_registry.all():
listeners.append(self._listener_info(binding))
return command_bindings.RuntimeSnapshot(listeners=listeners)
def _listener_info(self, binding: Any) -> Any:
listener = getattr(binding, "listener", None)
status = None
if listener is not None:
status_getter = getattr(listener, "status", None)
if callable(status_getter):
try:
status = status_getter()
except Exception:
status = None
listener_type = str(getattr(status, "source_type", "") or "")
if not listener_type and listener is not None:
listener_type = _default_listener_type(listener)
listener_state = _enum_text(getattr(status, "lifecycle_state", None))
if not listener_state:
listener_state = EventLifecycleState.CREATED.value
return command_bindings.ListenerInfo(
name=str(getattr(binding, "name", "") or ""),
type=listener_type,
enable=bool(getattr(binding, "enabled", False)),
state=listener_state,
)

View File

@ -25,6 +25,8 @@ CommandRequestPayload: Any = getattr(commands_pb2, "CommandRequestPayload")
CommandRequestEnvelope: Any = getattr(commands_pb2, "CommandRequestEnvelope")
CommandRequestHeader: Any = getattr(commands_pb2, "CommandRequestHeader")
CommandResultEnvelope: Any = getattr(commands_pb2, "CommandResultEnvelope")
ListenerInfo: Any = getattr(commands_pb2, "ListenerInfo")
RuntimeSnapshot: Any = getattr(commands_pb2, "RuntimeSnapshot")
CommandResultHeader: Any = getattr(commands_pb2, "CommandResultHeader")
CommandResultPayload: Any = getattr(commands_pb2, "CommandResultPayload")
CommandExecutionPolicy: Any = getattr(commands_pb2, "CommandExecutionPolicy")
@ -44,6 +46,8 @@ __all__ = [
"CommandRequestEnvelope",
"CommandRequestHeader",
"CommandResultEnvelope",
"ListenerInfo",
"RuntimeSnapshot",
"CommandResultHeader",
"CommandResultPayload",
"CommandExecutionPolicy",

View File

@ -11,10 +11,12 @@ from app.shared.contracts.proto.v1.northbound_bindings import (
CommandTarget,
ErrorResponse,
EventMessage,
ListenerInfo,
Ping,
Pong,
ServerEnvelope,
ServerHello,
RuntimeSnapshot,
SessionStateUpdate,
SubscribeRequest,
UnsubscribeRequest,
@ -38,4 +40,6 @@ __all__ = [
"SessionStateUpdate",
"Ping",
"Pong",
"ListenerInfo",
"RuntimeSnapshot",
]

View File

@ -43,6 +43,17 @@ message CommandResultEnvelope {
CommandResultPayload payload = 3;
}
message ListenerInfo {
string name = 1;
string type = 2;
bool enable = 3;
string state = 4;
}
message RuntimeSnapshot {
repeated ListenerInfo listeners = 1;
}
message CommandResultHeader {
string command_kind = 1;
string executor_type = 2;
@ -62,6 +73,7 @@ message CommandResultPayload {
KeyValueList kv = 3;
StructuredFields structured = 4;
ErrorInfo error = 5;
RuntimeSnapshot runtime_snapshot = 6;
}
}

View File

@ -96,6 +96,7 @@ message CommandResponseMessage {
wfagent.proto.v1.KeyValueList kv = 11;
wfagent.proto.v1.StructuredFields structured = 12;
wfagent.proto.v1.ErrorInfo error = 13;
wfagent.proto.v1.RuntimeSnapshot runtime_snapshot = 14;
}
}

View File

@ -12,6 +12,7 @@ if _GENERATED_PATH not in sys.path:
sys.path.insert(0, _GENERATED_PATH)
northbound_pb2 = importlib.import_module("northbound_pb2")
commands_pb2 = importlib.import_module("commands_pb2")
ClientEnvelope: Any = getattr(northbound_pb2, "ClientEnvelope")
ServerEnvelope: Any = getattr(northbound_pb2, "ServerEnvelope")
@ -30,6 +31,8 @@ ErrorResponse: Any = getattr(northbound_pb2, "ErrorResponse")
SessionStateUpdate: Any = getattr(northbound_pb2, "SessionStateUpdate")
Ping: Any = getattr(northbound_pb2, "Ping")
Pong: Any = getattr(northbound_pb2, "Pong")
ListenerInfo: Any = getattr(commands_pb2, "ListenerInfo")
RuntimeSnapshot: Any = getattr(commands_pb2, "RuntimeSnapshot")
__all__ = [
"ClientEnvelope",
@ -49,4 +52,6 @@ __all__ = [
"SessionStateUpdate",
"Ping",
"Pong",
"ListenerInfo",
"RuntimeSnapshot",
]

View File

@ -223,3 +223,97 @@ def test_cli_command_flow_integration_cancel(tmp_path: Path, capsys) -> None:
assert "state=CANCELLED" in captured.out
assert "text=cancelled" in captured.out
def test_cli_command_flow_integration_runtime_snapshot(
tmp_path: Path, capsys
) -> None:
root = tmp_path / "app.toml"
_make_root_config(root, bridge_port=18107)
async def handler(websocket: Any) -> None:
hello = _parse_client_envelope(await websocket.recv())
assert hello.message_kind == "CLIENT_HELLO"
await websocket.send(
command_northbound_bindings.ServerEnvelope(
protocol_version="1.0",
message_kind="SERVER_HELLO",
session_id="session-1",
sent_at_unix_ms=1,
server_hello=command_northbound_bindings.ServerHello(
server_name="wf-agent",
protocol_version="1.0",
server_version="0.1.0",
),
).SerializeToString()
)
request = _parse_client_envelope(await websocket.recv())
assert request.message_kind == "COMMAND_REQUEST"
assert request.command_request.command.command_kind == "get_runtime_snapshot"
await websocket.send(
command_northbound_bindings.ServerEnvelope(
protocol_version="1.0",
message_kind="COMMAND_RESPONSE",
session_id="session-1",
request_id=request.request_id,
correlation_id=request.correlation_id,
sent_at_unix_ms=2,
command_response=command_northbound_bindings.CommandResponseMessage(
status="SUCCEEDED",
command_kind="get_runtime_snapshot",
target_type="app",
target_id="wf-agent",
started_at_unix_ms=3,
finished_at_unix_ms=4,
runtime_snapshot=command_northbound_bindings.RuntimeSnapshot(
listeners=[
command_northbound_bindings.ListenerInfo(
name="file-events",
type="file",
enable=True,
state="RECEIVED",
)
]
),
),
).SerializeToString()
)
async def scenario() -> None:
server, port = await _run_server(handler)
try:
root.write_text(
root.read_text(encoding="utf-8").replace(
"bind_port = 18107", f"bind_port = {port}"
),
encoding="utf-8",
)
exit_code = await asyncio.to_thread(
main,
[
"--config-file",
str(root),
"submit",
"--command-kind",
"get_runtime_snapshot",
"--target-type",
"app",
"--target-id",
"wf-agent",
"--command-name",
"get_runtime_snapshot",
"--timeout-sec",
"0.2",
],
)
assert exit_code == 0
finally:
server.close()
await server.wait_closed()
asyncio.run(scenario())
captured = capsys.readouterr()
assert "runtime snapshot listeners=[" in captured.out
assert "name=file-events" in captured.out
assert "enable=true" in captured.out

View File

@ -114,6 +114,41 @@ def _make_error_envelope() -> Any:
)
def _make_runtime_snapshot_envelope() -> Any:
return northbound_bindings.ServerEnvelope(
protocol_version="1.0",
message_kind="COMMAND_RESPONSE",
session_id="session-1",
request_id="request-1",
correlation_id="corr-1",
sent_at_unix_ms=125,
command_response=northbound_bindings.CommandResponseMessage(
status="SUCCEEDED",
command_kind="get_runtime_snapshot",
target_type="app",
target_id="wf-agent",
started_at_unix_ms=126,
finished_at_unix_ms=127,
runtime_snapshot=northbound_bindings.RuntimeSnapshot(
listeners=[
northbound_bindings.ListenerInfo(
name="file-events",
type="file",
enable=True,
state="RECEIVED",
),
northbound_bindings.ListenerInfo(
name="dbus-events",
type="dbus",
enable=False,
state="DISPATCHED",
),
]
),
),
)
async def _run_server(handler: Any) -> tuple[Any, int]:
import websockets
@ -167,6 +202,20 @@ def test_render_server_envelope_error():
assert "details=temporary transport error" in rendered
def test_render_server_envelope_runtime_snapshot():
rendered = render_server_envelope(
_make_runtime_snapshot_envelope(), output_mode="human"
)
assert "runtime snapshot listeners=[" in rendered
assert "name=file-events" in rendered
assert "type=file" in rendered
assert "enable=true" in rendered
assert "state=RECEIVED" in rendered
assert "name=dbus-events" in rendered
assert "enable=false" in rendered
def test_cli_subscription_command_renders_human_output(tmp_path: Path, capsys) -> None:
root = tmp_path / "app.toml"
_make_root_config(root, bridge_port=18100)

View File

@ -171,3 +171,50 @@ def test_command_bridge_maps_results_and_rejects_invalid_requests() -> None:
assert invalid_response.message_kind == "ERROR"
assert invalid_response.error.error_code == CommandErrorCode.VALIDATION_FAILED.value
assert bridge.status().rejected_count >= 1
def test_command_bridge_codec_preserves_runtime_snapshot_results() -> None:
codec = CommandBridgeNorthboundCodec(server_name="wf-agent", server_version="1")
runtime_snapshot = command_bindings.RuntimeSnapshot(
listeners=[
command_bindings.ListenerInfo(
name="file-events",
type="file",
enable=True,
state="RECEIVED",
)
]
)
result = command_bindings.CommandResultEnvelope(
meta=command_bindings.Meta(
message_id="cmd-4",
correlation_id="corr-4",
created_at_unix_ms=123,
),
header=command_bindings.CommandResultHeader(
command_kind="get_runtime_snapshot",
executor_type="runtime_snapshot",
executor_id="runtime-snapshot-executor",
target_type="app",
target_id="wf-agent",
status="succeeded",
started_at_unix_ms=456,
finished_at_unix_ms=789,
exit_code=0,
),
payload=command_bindings.CommandResultPayload(
runtime_snapshot=runtime_snapshot
),
)
response = codec.build_command_response_from_result(
result,
session_id="session-1",
request_id="request-1",
correlation_id="corr-1",
)
assert response.message_kind == "COMMAND_RESPONSE"
assert response.command_response.WhichOneof("result") == "runtime_snapshot"
assert response.command_response.runtime_snapshot.listeners[0].name == "file-events"
assert response.command_response.runtime_snapshot.listeners[0].enable is True

View File

@ -101,3 +101,49 @@ def test_command_result_and_spool_bindings_round_trip():
assert parsed_result.payload.text == "done"
assert parsed_spool_item.state.spool_state == "READY"
assert parsed_spool_item.policy.failure_policy == "MARK_FAILED"
def test_command_runtime_snapshot_bindings_round_trip() -> None:
snapshot = command_bindings.RuntimeSnapshot(
listeners=[
command_bindings.ListenerInfo(
name="file-events",
type="file",
enable=True,
state="RECEIVED",
),
command_bindings.ListenerInfo(
name="dbus-events",
type="dbus",
enable=False,
state="CREATED",
),
]
)
result = command_bindings.CommandResultEnvelope(
meta=command_bindings.Meta(
message_id="cmd-2",
created_at_unix_ms=124,
),
header=command_bindings.CommandResultHeader(
command_kind="get_runtime_snapshot",
executor_type="runtime_snapshot",
executor_id="runtime-snapshot-executor",
target_type="app",
target_id="wf-agent",
status="succeeded",
started_at_unix_ms=125,
finished_at_unix_ms=126,
exit_code=0,
),
payload=command_bindings.CommandResultPayload(runtime_snapshot=snapshot),
)
parsed_result = command_bindings.CommandResultEnvelope.FromString(
result.SerializeToString()
)
assert parsed_result.payload.WhichOneof("body") == "runtime_snapshot"
assert parsed_result.payload.runtime_snapshot.listeners[0].name == "file-events"
assert parsed_result.payload.runtime_snapshot.listeners[0].enable is True
assert parsed_result.payload.runtime_snapshot.listeners[1].state == "CREATED"

View File

@ -91,3 +91,40 @@ def test_event_bridge_northbound_codec_builds_protocol_envelopes():
assert event_envelope.event.event_type == "wifi.status"
assert event_envelope.event.text == "connected"
assert error_envelope.error.error_code == EventErrorCode.BRIDGE_FAILED.value
def test_northbound_runtime_snapshot_bindings_round_trip() -> None:
envelope = northbound_bindings.ServerEnvelope(
protocol_version="1.0",
message_kind="COMMAND_RESPONSE",
session_id="session-1",
request_id="request-1",
correlation_id="corr-1",
sent_at_unix_ms=123,
command_response=northbound_bindings.CommandResponseMessage(
status="SUCCEEDED",
command_kind="get_runtime_snapshot",
target_type="app",
target_id="wf-agent",
started_at_unix_ms=456,
finished_at_unix_ms=789,
runtime_snapshot=northbound_bindings.RuntimeSnapshot(
listeners=[
northbound_bindings.ListenerInfo(
name="file-events",
type="file",
enable=True,
state="RECEIVED",
)
]
),
),
)
parsed = northbound_bindings.ServerEnvelope.FromString(
envelope.SerializeToString()
)
assert parsed.message_kind == "COMMAND_RESPONSE"
assert parsed.command_response.WhichOneof("result") == "runtime_snapshot"
assert parsed.command_response.runtime_snapshot.listeners[0].name == "file-events"

View File

@ -0,0 +1,60 @@
from __future__ import annotations
from app.command import (
CommandExecutionContext,
GetRuntimeSnapshotCommandExecutor,
)
from app.shared.contracts.proto.v1 import command_bindings
class _SnapshotProvider:
def __init__(self, snapshot: object) -> None:
self._snapshot = snapshot
def snapshot(self) -> object:
return self._snapshot
def _make_request() -> object:
return command_bindings.CommandRequestEnvelope(
meta=command_bindings.Meta(
message_id="cmd-1",
created_at_unix_ms=1,
),
header=command_bindings.CommandRequestHeader(
command_kind="get_runtime_snapshot",
target_type="app",
target_id="wf-agent",
issuer_type="cli",
issuer_id="host-default",
expects_response=True,
),
payload=command_bindings.CommandRequestPayload(),
)
def test_runtime_snapshot_executor_returns_typed_snapshot() -> None:
snapshot = command_bindings.RuntimeSnapshot(
listeners=[
command_bindings.ListenerInfo(
name="file-events",
type="file",
enable=True,
state="RECEIVED",
)
]
)
executor = GetRuntimeSnapshotCommandExecutor(
snapshot_provider=_SnapshotProvider(snapshot)
)
request = _make_request()
result = executor.execute(
request, CommandExecutionContext(request=request)
)
assert result.header.command_kind == "get_runtime_snapshot"
assert result.payload.WhichOneof("body") == "runtime_snapshot"
assert result.payload.runtime_snapshot.listeners[0].name == "file-events"
assert result.payload.runtime_snapshot.listeners[0].enable is True
assert executor.status().last_command_kind == "get_runtime_snapshot"

View File

@ -0,0 +1,74 @@
from __future__ import annotations
from app.event import (
EventComponentKind,
EventLifecycleState,
EventListenerStatus,
EventRuntimeSettings,
build_event_runtime,
)
from app.runtime.snapshot import RuntimeSnapshotService
class _SnapshotListener:
def __init__(
self,
name: str,
*,
source_type: str,
lifecycle_state: EventLifecycleState,
) -> None:
self.name = name
self._status = EventListenerStatus(
component_kind=EventComponentKind.LISTENER,
component_name=name,
lifecycle_state=lifecycle_state,
source_type=source_type,
source_id=f"{source_type}-source",
)
def start(self, publisher: object) -> None:
_ = publisher
raise RuntimeError("not used")
def stop(self) -> None:
return None
def status(self) -> EventListenerStatus:
return self._status
def test_runtime_snapshot_service_reads_listener_registry_state() -> None:
runtime = build_event_runtime(
listener_factories={
"file-events": lambda: _SnapshotListener(
"file-events",
source_type="file",
lifecycle_state=EventLifecycleState.RECEIVED,
),
"dbus-events": lambda: _SnapshotListener(
"dbus-events",
source_type="dbus",
lifecycle_state=EventLifecycleState.DISPATCHED,
),
},
settings=EventRuntimeSettings(
listener_enabled={"file-events": True, "dbus-events": False}
),
)
snapshot = RuntimeSnapshotService(runtime).snapshot()
assert [listener.name for listener in snapshot.listeners] == [
"file-events",
"dbus-events",
]
assert [listener.type for listener in snapshot.listeners] == [
"file",
"dbus",
]
assert [listener.enable for listener in snapshot.listeners] == [True, False]
assert [listener.state for listener in snapshot.listeners] == [
"RECEIVED",
"DISPATCHED",
]

View File

@ -0,0 +1,217 @@
from __future__ import annotations
from pathlib import Path
from threading import Event
from types import SimpleNamespace
from typing import Any
import app.main.app as app_main
from app.event import (
EventComponentKind,
EventLifecycleState,
EventListenerStatus,
EventRuntimeSettings,
build_event_runtime,
)
from app.shared.contracts.proto.v1 import command_bindings
class _SnapshotListener:
def __init__(
self,
name: str,
*,
source_type: str,
lifecycle_state: EventLifecycleState,
) -> None:
self.name = name
self._status = EventListenerStatus(
component_kind=EventComponentKind.LISTENER,
component_name=name,
lifecycle_state=lifecycle_state,
source_type=source_type,
source_id=f"{source_type}-source",
)
def start(self, publisher: object) -> None:
_ = publisher
raise RuntimeError("not used")
def stop(self) -> None:
return None
def status(self) -> EventListenerStatus:
return self._status
class _DummyOrchestrator:
def __init__(self, status: Any) -> None:
self._status = status
def start(self) -> None:
return None
def stop(self, *args: Any, **kwargs: Any) -> None:
_ = args, kwargs
def join(self, *args: Any, **kwargs: Any) -> None:
_ = args, kwargs
def status(self) -> Any:
return self._status
def is_running(self) -> bool:
return False
def _make_root_config(path: Path) -> None:
path.write_text(
"\n".join(
[
"includes = []",
"",
"[app]",
'name = "wf-agent-gen4"',
'instance_id = "host-default"',
"",
"[event_dispatcher]",
"enabled = true",
"",
"[command_dispatcher]",
"enabled = true",
"",
"[command_bridge]",
"enabled = false",
"",
]
),
encoding="utf-8",
)
def test_backend_registers_runtime_snapshot_executor_after_event_runtime_exists(
tmp_path: Path, monkeypatch: Any
) -> None:
root = tmp_path / "app.toml"
_make_root_config(root)
runtime = build_event_runtime(
listener_factories={
"file-events": lambda: _SnapshotListener(
"file-events",
source_type="file",
lifecycle_state=EventLifecycleState.RECEIVED,
),
"dbus-events": lambda: _SnapshotListener(
"dbus-events",
source_type="dbus",
lifecycle_state=EventLifecycleState.DISPATCHED,
),
},
settings=EventRuntimeSettings(
listener_enabled={"file-events": True, "dbus-events": False}
),
)
order: list[str] = []
captured: dict[str, Any] = {}
def fake_build_event_runtime(*args: Any, **kwargs: Any) -> Any:
_ = args, kwargs
order.append("event_runtime")
return runtime
def fake_build_command_runtime(*args: Any, **kwargs: Any) -> Any:
_ = args
order.append("command_runtime")
captured["executor_factories"] = kwargs["executor_factories"]
return SimpleNamespace(websocket_transport=None)
def fake_build_event_runtime_orchestrator(runtime_arg: Any, **kwargs: Any) -> Any:
_ = kwargs
assert runtime_arg is runtime
status = SimpleNamespace(
healthy=True,
lifecycle_state=SimpleNamespace(value="STOPPED"),
listener_count=2,
running_listener_count=0,
completed_listener_count=0,
failed_listener_count=0,
bridge_cycle_count=0,
delivered_event_count=0,
websocket_server_started=False,
dispatch_cycle_count=0,
cron_cycle_count=0,
)
return _DummyOrchestrator(status)
def fake_build_command_runtime_orchestrator(
runtime_arg: Any, *, dispatch_poll_interval_sec: float, shutdown_drain_timeout_sec: float
) -> Any:
_ = dispatch_poll_interval_sec, shutdown_drain_timeout_sec
assert runtime_arg.websocket_transport is None
status = SimpleNamespace(
healthy=True,
lifecycle_state=SimpleNamespace(value="STOPPED"),
listener_count=0,
running_listener_count=0,
completed_listener_count=0,
failed_listener_count=0,
bridge_cycle_count=0,
delivered_event_count=0,
websocket_server_started=False,
dispatch_cycle_count=0,
cron_cycle_count=0,
)
return _DummyOrchestrator(status)
monkeypatch.setattr("app.main.app.build_event_runtime", fake_build_event_runtime)
monkeypatch.setattr("app.main.app.build_command_runtime", fake_build_command_runtime)
monkeypatch.setattr(
"app.main.app.build_event_runtime_orchestrator",
fake_build_event_runtime_orchestrator,
)
monkeypatch.setattr(
"app.main.app.build_command_runtime_orchestrator",
fake_build_command_runtime_orchestrator,
)
shutdown_event = Event()
shutdown_event.set()
assert app_main.run_backend_service(root, shutdown_event=shutdown_event) == 0
assert order == ["event_runtime", "command_runtime"]
executor_factory = captured["executor_factories"]["runtime_snapshot"]
executor = executor_factory()
request = command_bindings.CommandRequestEnvelope(
meta=command_bindings.Meta(
message_id="cmd-1",
created_at_unix_ms=1,
),
header=command_bindings.CommandRequestHeader(
command_kind="get_runtime_snapshot",
target_type="app",
target_id="wf-agent",
issuer_type="cli",
issuer_id="host-default",
expects_response=True,
),
payload=command_bindings.CommandRequestPayload(),
)
result = executor.execute(request, object())
assert result.payload.WhichOneof("body") == "runtime_snapshot"
assert [item.name for item in result.payload.runtime_snapshot.listeners] == [
"file-events",
"dbus-events",
]
assert [item.enable for item in result.payload.runtime_snapshot.listeners] == [
True,
False,
]
assert [item.state for item in result.payload.runtime_snapshot.listeners] == [
"RECEIVED",
"DISPATCHED",
]