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

Add device extensions support #228

Merged
merged 1 commit into from
Nov 20, 2024
Merged

Add device extensions support #228

merged 1 commit into from
Nov 20, 2024

Conversation

jjcarstens
Copy link
Collaborator

@jjcarstens jjcarstens commented Sep 1, 2024

Next idea of the previously defined "extensions"

This adds the mechanism to handle features on a device for custom data and/or reporting outside the update mechanism. Features are isolated from the socket as to not get in the way of potential updates and can be defined in external libs as well as this one by implementing the NervesHubLink.Extensions behavior.

@@ -481,7 +506,7 @@ defmodule NervesHubLink.Socket do
_ = Client.handle_error(reason)
end

rejoin(socket, topic, socket.assigns.params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are the params removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant to comment. The slipstream default is to reuse the params that were sent in the initial join. With the addition of features channel, this was sending the generic firmware metadata params in the event of the features channel closing and rejoining.

I could have pattern matched on the channel name to selectively choose, or just let slipstream send the default original params (which are already static anyway, so no need to forcefully send)

Comment on lines 203 to 208
name = opts[:name] || raise "Missing required feature arg: name"
version = opts[:version] || raise "Missing required feature arg: version"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to being arguments to the use macro rather than callbacks so that it can be enforced at compile time vs just a warning (not everyone has --warnings-as-errors flag by default)

These need some typing and docs that will come later as I'm out of time for a bit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshk
Copy link
Contributor

joshk commented Sep 3, 2024

Honestly, this code is looking solid to me!

@lawik lawik mentioned this pull request Sep 3, 2024
Copy link
Contributor

@lawik lawik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to add. Should work well :)

Is there anything that needs to be rounded out or added?

@@ -0,0 +1,22 @@
defmodule NervesHubLink.Features.Geo.Resolver do
@typedoc "Supported location sources"
@type sources() :: :gps | :geoip | :custom
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since users can add their own this should probably be a string :)
(was this lifted from geo, if so, kind of irrelevant to the PR)

Or {:custom, "where_i_put_it"} style. Give us something to display in UI about how it gets it's data.

@lawik lawik marked this pull request as ready for review October 28, 2024 16:02
@lawik
Copy link
Contributor

lawik commented Oct 28, 2024

Rebasing but should be good to review @joshk

This has had geo and health integrated into it.

I like the new abstraction. Nice and friendly.

@lawik
Copy link
Contributor

lawik commented Nov 12, 2024

Link won't load the Feature modules if run iex -S mix in dev mode. I'm fairly sure it would load more agressively in production compile on-device but this seems not ideal. Essentially a race condition between the socket going up and the library figuring out if it has features?

I tried changing it to not just run find_features/0 on init but rather on list/0 but that didn't really help.

@lawik
Copy link
Contributor

lawik commented Nov 12, 2024

I suppose since we plan on controlling this from nerves_hub_link we could provide a default discoverability for health and geo and then let people configure if they have more or other sets they want.

I'll move this to config.

@lawik
Copy link
Contributor

lawik commented Nov 12, 2024

Running this and nerves_hub_web locally, catching a bunch of trickiness :)

@jjcarstens
Copy link
Collaborator Author

It's because of how modules are loaded (i.e. :interactive vs :embedded). I noticed this last night as well:

iex(8)> NervesHubLink.Features.find_features
%{}

# This first call forces the module to load
iex(9)> NervesHubLink.Features.Geo.module_info :attributes
[
  vsn: [11907264823846348490321455620962448498],
  behaviour: [GenServer],
  behaviour: [NervesHubLink.Features]
]

iex(10)> NervesHubLink.Features.find_features
%{
  "geo" => %{
    module: NervesHubLink.Features.Geo,
    version: "0.0.1",
    attached?: false
  }
}

@lawik
Copy link
Contributor

lawik commented Nov 12, 2024

Yeah, I know. I switched it to config. Argue if you disagree :D

@lawik lawik force-pushed the features-support branch 2 times, most recently from 5e2ca0b to b044770 Compare November 19, 2024 14:27
@lawik
Copy link
Contributor

lawik commented Nov 19, 2024

@jjcarstens @joshk please review this now, kindly, I think it is done

@lawik lawik requested review from joshk and removed request for oestrich November 19, 2024 14:28
@lawik lawik changed the title Add device features support Add device extensions support Nov 19, 2024
Copy link
Contributor

@nshoes nshoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally LGTM, just some small nits, nothing blocking.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved

## Configure Geo

It is intended to be easy to replace the default Geo Resolver with your own. Maybe you have a GPS module or can resolve a reasonably precise location via LTE. Just change config:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It is intended to be easy to replace the default Geo Resolver with your own. Maybe you have a GPS module or can resolve a reasonably precise location via LTE. Just change config:
It is intended to be easy to replace the default Geo Resolver with your own. Maybe you have a GPS module or can resolve a reasonably precise location via LTE. Just change the config:

README.md Outdated Show resolved Hide resolved
lib/nerves_hub_link/extensions/extensions.ex Outdated Show resolved Hide resolved
lib/nerves_hub_link/socket.ex Outdated Show resolved Hide resolved
This adds the mechanism to handle extensions on a device for custom
data and/or reporting outside the firmware update mechanism. Extensions
are isolated from the socket as to not get in the way of potential
firmware updates and can be defined in external libs as well as this
one by implementing the `NervesHubLink.Extensions` behavior

- Implements Geo and Health modules as examples of Extensions
- All Extensions currently report only on request from NervesHub
- Add optional vintage_net dependency to allow fetching interfaces
@lawik
Copy link
Contributor

lawik commented Nov 20, 2024

Good nit-hunt @nshoes, much appreciated :)

@lawik lawik merged commit f0a9e84 into main Nov 20, 2024
5 checks passed
@lawik lawik deleted the features-support branch November 20, 2024 11:32
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

Successfully merging this pull request may close these issues.

5 participants