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

Track basic farmOS metrics #22

Open
paul121 opened this issue Oct 3, 2019 · 5 comments
Open

Track basic farmOS metrics #22

paul121 opened this issue Oct 3, 2019 · 5 comments
Labels
enhancement New feature or request

Comments

@paul121
Copy link
Member

paul121 commented Oct 3, 2019

The idea here is to be able to aggregate metrics from a farmOS instance. The specific metrics would depend on each use case of the Aggregator. For a crowdsourced community aggregator (described here in farmOS/farmOS#206) basic metrics might be a farm location, total area, number of users, and simple farm "profile" information.

@paul121 paul121 added the enhancement New feature or request label Oct 3, 2019
@mstenta mstenta mentioned this issue Oct 3, 2019
5 tasks
@paul121 paul121 added this to the v1.1.0 milestone Oct 3, 2019
@mstenta
Copy link
Member

mstenta commented Oct 5, 2019

That would be great. I recently added a "Metrics" pane to the farm dashboard with this kind of information - so perhaps we could serve that via the API too in a way that the aggregator could easily consume. Either that, or replicate the logic in the aggregator.

Screenshot from 2019-10-05 15-40-41

@paul121
Copy link
Member Author

paul121 commented Oct 6, 2019

Oh I forgot about that Metrics pane! That's a great start. I think having a /metrics API endpoint would make sense. I'm trying to brainstorm how we can "scope" this out, too. Farms should be able to (easily) choose which metrics are made visible. An easy way would be to make config page with a Drupal Form to configure which "metrics" to expose via the API.

An alternative might be to make separate endpoints /metrics/area/, /metrics/animals/, /metrics/.... and have each endpoint attached to a OAuth Scope - the user can allow which metrics to include when authorizing an Aggregator via OAuth

@mstenta
Copy link
Member

mstenta commented Oct 7, 2019

Metrics are currently handled by the farm_dashboard module - but if we want them to be used outside of the dashboard they should probably become their own module (farm_metrics perhaps).

Metrics can be added to the dashboard by other modules by implementing hook_farm_dashboard_metrics(). Here is the API documentation example:

https://github.com/farmOS/farmOS/blob/7.x-1.x/modules/farm/farm_dashboard/farm_dashboard.api.php#L54

Here is an implementation of that hook in the farm_area module, which adds metrics for number of areas, and total area:

https://github.com/farmOS/farmOS/blob/7.x-1.x/modules/farm/farm_area/farm_area.farm_dashboard.inc#L31

So maybe the next step would be to break that stuff out to a new farm_metrics module, and then simple implement hook_farm_info() in farm_metrics.module to add metrics to /farm.json (rather than add a new endpoint just for metrics - although that could also be justified).

the user can allow which metrics to include when authorizing an Aggregator via OAuth

This is a good consideration. Right now there aren't granular permissions for metrics. I think the "right" approach would be for them to be based on the existing permissions (eg: "view all animal assets"), rather than providing new permissions just for metrics.

@mstenta mstenta modified the milestones: v1.1.0, Public farmOS Aggregator Oct 22, 2019
@paul121
Copy link
Member Author

paul121 commented Dec 31, 2019

Currently the aggregator is caching info returned via API at /farm.json. This doesn't include any metrics necessarily, but is worth noting. It is fairly easy to implement with PostgresDB JSONB storage in the DB. We could add more info to /farm.json with a farm_metrics module and that would then automatically start getting cached.

Alternatively, if we were to add a /metrics endpoint to farmOS, we would need to update the farmOS.py client with a method to retrieve that info. This might be better if there are advantages to having a separate /metrics/ endpoint. For OAuth scopes it might be easier to put separate endpoints in separate scopes, or just provide different amounts of data within the same scope

@paul121
Copy link
Member Author

paul121 commented Jan 29, 2020

PR that adds a farm_metrics farmOS/farmOS#230 - note this doesn't include a farm_metrics scope, but that could be added with OAuth farmOS/farmOS#207

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants