Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Feb 16, 2024
1 parent a653b35 commit 598701e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions osf/metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# osf.metrics

`osf.metrics` allows storing anonymized usage data and defining periodic
reports based on that data.

the data model was built to be [COUNTER](https://cop5.projectcounter.org/en/5.0.2/)-compliant,
but note that the COUNTER_SUSHI api has not yet been implemented atop.

## data model
usage data and periodic reports are both stored in elasticsearch using
`elasticsearch-dsl`-based data models.

each "usage" is represented as `CountedAuthUsage` -- see `osf.metrics.counted_usage`
for field definitions with comments mapping fields to concepts in the COUNTER spec.

each periodic report is represented as a subclass of `DailyReport` or `MonthlyReport`
(see `osf.metrics.reports`) and has a "reporter" (see `osf.metrics.reporters`) that
is invoked periodically to report.

## api
note: the `osf.metrics` api is subject to change, is supported only for use within OSF
(use at your own risk!), and may someday be mostly replaced by a
[COUNTER_SUSHI api](https://cop5.projectcounter.org/en/5.0.2/08-sushi/index.html).

the `osf.metrics` api is currently located under the osf api namespace `/_/metrics/`,
and contains a variety of special-purpose endpoints (see `api.metrics.urls` for a full accounting).

endpoints of interest for new development (all starting with `/_/metrics/`):
- `events/counted_usage/`: POST-only, for recording a usage
- `reports/`: GET list of available report types
- `reports/<report-id>/recent`: GET list of recent reports
- `query/`: namespace for views that query usage data on demand (only for statically defined, cheap queries)

## how to

### add a new monthly report
- add a `MonthlyReport` subclass (in `osf.metrics.reports`) with the fields you want
- add a `MonthlyReporter` subclass (in a module under `osf.metrics.reporters`)
that knows how to build your report
- to have your reporter run automatically, add it to `osf.metrics.reporters.MONTHLY_REPORTERS`
- to have your report available in the api, add it to `api.metrics.views.VIEWABLE_REPORTS`

0 comments on commit 598701e

Please sign in to comment.