autoprint other types of telemetry when returned from --request-telemetry #691
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #691 +/- ##
==========================================
- Coverage 60.68% 60.57% -0.12%
==========================================
Files 24 24
Lines 3770 3777 +7
==========================================
Hits 2288 2288
- Misses 1482 1489 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
Nice, this is a straightforward way to do it. Agreed on the JSON format, too. That, at least, can pretty straightforwardly match the protobufs, hopefully, but need to get the wiring in place and all that (excuses excuses, I know). I could swear I'd checked and thought the response function was already doing something like this, but I was clearly more tired than I thought when I did that PR, heh. Thanks for finding my mistake/putting up a solution! |
| if telemetry.device_metrics.uptime_seconds is not None: | ||
| print(f"Uptime: {telemetry.device_metrics.uptime_seconds} s") | ||
| else: | ||
| # this is the new code if --request-telemetry <type> is used. |
There was a problem hiding this comment.
Probably need to add a guard for some sort of 'received empty or garbled TELEMETRY_APP packet' here. Otherwise we'll choke on this. The old version at least checked for telemetry.HasField("device_metrics")
There was a problem hiding this comment.
Since we're parsing the protobuf out of the payload up above on line 662, I think it wouldn't get here at all if it's garbled in some fashion we could usefully detect. If it got an empty value back, the MessageToDict wouldn't have keys in it anyway, so it'd just print "Telemetry received:" and then nothing. Which, while a little confusing, probably not a big deal. I guess maybe it'd be reasonable to check what happens when requesting telemetry types not supported by a given node, since that'd possibly (probably?) return a payload with the right oneof selected but nothing to put into it. But I think it'd still print something comprehensible enough, so not too worried about it.
Fixes #690.
I didn't want to break the existing output from
device_metricsin case people are depending on that specific format, but this is begging for a--jsonswitch in the future.This approach (iterating and printing keys) should make the output more future proof if/when the protobufs change over time.
Example when requesting !device_metrics:
Example when not specifying a type, or when specifically requesting
device: