Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Motivation and design thoughts #7

Open
3 tasks done
MathiasKoch opened this issue Nov 15, 2020 · 7 comments
Open
3 tasks done

[RFC] Motivation and design thoughts #7

MathiasKoch opened this issue Nov 15, 2020 · 7 comments

Comments

@MathiasKoch
Copy link
Member

MathiasKoch commented Nov 15, 2020

This is our company RFC for the feature, copied here to give people an insight into the thoughts and usecase behind this crate.

Motivation

Currently all logging have been changed to use defmt (https://defmt.ferrous-systems.com/), which makes for a fast debug logging framework.

We should be able to use the two facts about defmt that it is transfer-agnostic and small sized on device to implement a global logger that writes to our external flash instead of RTT.

Background knowledge

NOTE This is slightly outdated, as the format of defmt has been changed to use tags and JSON, but for this project, the description is valid nevertheless.

The way defmtworks is:
Say we have a log statement defmt::info!("This would be awesome to log, but contains a lot of characters that is expensive to include in my binary! This is a variable: {:?}", 5), it would store the string This would be awesome to log, but contains a lot of characters that is expensive to include in my binary! This is a variable: {:?} in a debug section of the ELF, that would not be flashed onto the device, at a known index (in this example index 1).

The log statement on the device would then be changed to send

let bytes = [
    1,  // index
    2,  // timestamp
    5,  // argument
];

through whatever global logger transport is enabled on the device (eg. defmt-rtt)

The timestamp is generated from a function on the device, and could be an actual timestamp (eg. UTC), or just an incrementing number (eg. 1, 2, 3).

A decoder would then be needed to decode these bytes, based on the original ELF containing the aforementioned debug section.

This means that the logging itself is completely transport agnostic (could be serial based, network based, stored and read or whatever. As long as the ELF on the device matches the one used by the decoder)

Proposed Solution

The proposed solution involves writing a defmt-persist crate, that initializes a global logger to write to a given flash area.
The flash area should have an MQTT based API to read the log messages, eg. write to <DeviceType>/log/get/<UUID> and the device will start publishing log statements to <DeviceType>/log/<UUID> or something similar.
Furthermore we need some tooling to read logs and decode them based on the matching elf file from S3.

Implementation Steps

Changes needed to implement the feature:

Follow-up task would be to have devices send the full log to MQTT in case of a panic, with a lambda/IoT rule to log it to cloudwatch automatically, so we always persist logs leading up to a panic

@eupn
Copy link
Contributor

eupn commented Jun 18, 2021

@MathiasKoch, now we can tick the third checkbox by including defmt-persist-print tool.

@MathiasKoch
Copy link
Member Author

Sure thing! How do you want to reference it?

@eupn
Copy link
Contributor

eupn commented Jun 18, 2021

@MathiasKoch dunno, let's just include the github repo link in brackets as it's done currently so others can find it when they'd need to decode saved logs.

@MathiasKoch
Copy link
Member Author

Something like that?

@eupn
Copy link
Contributor

eupn commented Jun 18, 2021

LGTM!

@MathiasKoch
Copy link
Member Author

MathiasKoch commented Jun 18, 2021

Just opened some issues to anchor some of the potential improvements discussed in your PR.

Did i miss any?

@eupn
Copy link
Contributor

eupn commented Jun 19, 2021

@MathiasKoch

Just opened some issues to anchor some of the potential improvements discussed in your PR.

Did i miss any?

I think no, good job!

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

No branches or pull requests

2 participants