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

stats: Implement Daily active accounts statistics #329

Merged
merged 1 commit into from
Mar 2, 2023

Conversation

ptrus
Copy link
Member

@ptrus ptrus commented Feb 24, 2023

This PR adds /{layer}/stats/active_accounts endpoint, which returns a timeline with daily number of active accounts per layer.

The API only supports daily buckets (the buckets in response are always 86400 seconds big), but it offers overlapping buckets (e.g. 5-minute bucket granularity as in the example below). The window size is fixed to 1 day, while the window step is configurable via config - 5 or 10 minute is likely ok to use in production deployment.

Example responses (on a minimally synced mainnet indexer):

curl http://localhost:8008/v1/consensus/stats/active_accounts?limit=5&window_step_seconds=300
{
    "window_size_seconds": 86400,
    "windows": [
        {
            "active_accounts": 1251,
            "window_end": "2022-04-16T02:35:00Z"
        },
        {
            "active_accounts": 1246,
            "window_end": "2022-04-16T02:30:00Z"
        },
        {
            "active_accounts": 1243,
            "window_end": "2022-04-16T02:25:00Z"
        },
        {
            "active_accounts": 1242,
            "window_end": "2022-04-16T02:20:00Z"
        },
        {
            "active_accounts": 1243,
            "window_end": "2022-04-16T02:15:00Z"
        }
    ]
}

curl http://localhost:8008/v1/consensus/stats/active_accounts?window_step_seconds=30
{"msg":"Invalid format for parameter window_step_seconds: invalid value: 30"}

curl http://localhost:8008/v1/consensus/stats/active_accounts
{
    "window_size_seconds": 86400,
    "windows": [
        {
            "active_accounts": 1230,
            "window_end": "2022-04-16T00:00:00Z"
        },
        {
            "active_accounts": 1326,
            "window_end": "2022-04-15T00:00:00Z"
        },
        {
            "active_accounts": 1367,
            "window_end": "2022-04-14T00:00:00Z"
        },
        {
            "active_accounts": 1119,
            "window_end": "2022-04-13T00:00:00Z"
        },
        {
            "active_accounts": 666,
            "window_end": "2022-04-12T00:00:00Z"
        }
    ]
}

curl http://localhost:8008/v1/emerald/stats/active_accounts?limit=5
{
    "window_size_seconds": 86400,
    "windows": [
        {
            "active_accounts": 3569,
            "window_end": "2022-04-15T00:00:00Z"
        },
        {
            "active_accounts": 3852,
            "window_end": "2022-04-14T00:00:00Z"
        },
        {
            "active_accounts": 3776,
            "window_end": "2022-04-13T00:00:00Z"
        },
        {
            "active_accounts": 2418,
            "window_end": "2022-04-12T00:00:00Z"
        }
    ]
}

TODO:

  • Run the updated analyzer on mainnet and sanity check the results
  • Likely some code cleanup

@ptrus ptrus force-pushed the ptrus/feature/analzyer-stats-activeacc branch 4 times, most recently from a9b4e89 to 0eaffa7 Compare February 24, 2023 21:16
storage/client/queries.go Outdated Show resolved Hide resolved
config/local-dev.yml Outdated Show resolved Hide resolved
@ptrus ptrus force-pushed the ptrus/feature/analzyer-stats-activeacc branch 2 times, most recently from 50a09b6 to 20c74f6 Compare February 27, 2023 17:51
Copy link
Collaborator

@mitjat mitjat left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!
I much appreciate the comments sprinkled everywhere, and the clean refactoring of existing code where needed.

I have some comments/suggestions, but nothing major.

analyzer/queries.go Outdated Show resolved Hide resolved
analyzer/aggregate_stats.go Outdated Show resolved Hide resolved
config/local-dev.yml Outdated Show resolved Hide resolved
storage/client/queries.go Outdated Show resolved Hide resolved
config/config.go Show resolved Hide resolved
analyzer/aggregate_stats.go Outdated Show resolved Hide resolved
config/local-dev.yml Outdated Show resolved Hide resolved
api/spec/v1.yaml Outdated Show resolved Hide resolved
api/spec/v1.yaml Show resolved Hide resolved
@ptrus ptrus force-pushed the ptrus/feature/analzyer-stats-activeacc branch 8 times, most recently from 34d33d8 to c3d0dec Compare February 28, 2023 16:54
@ptrus
Copy link
Member Author

ptrus commented Feb 28, 2023

Thanks for the thoughtful review, I think I addressed all the comments, please take another look @mitjat

@ptrus ptrus requested a review from mitjat February 28, 2023 16:54
@ptrus ptrus force-pushed the ptrus/feature/analzyer-stats-activeacc branch 4 times, most recently from 246866c to 8523f75 Compare March 2, 2023 13:36
Copy link
Collaborator

@mitjat mitjat left a comment

Choose a reason for hiding this comment

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

🎉

Only very minor comments left.

analyzer/aggregate_stats.go Show resolved Hide resolved
analyzer/aggregate_stats.go Outdated Show resolved Hide resolved
analyzer/aggregate_stats.go Outdated Show resolved Hide resolved
api/spec/v1.yaml Show resolved Hide resolved
api/spec/v1.yaml Show resolved Hide resolved
storage/migrations/03_agg_stats.up.sql Outdated Show resolved Hide resolved
tests/e2e_regression/run.sh Outdated Show resolved Hide resolved
storage/client/client.go Outdated Show resolved Hide resolved
analyzer/aggregate_stats.go Outdated Show resolved Hide resolved
@ptrus ptrus force-pushed the ptrus/feature/analzyer-stats-activeacc branch 2 times, most recently from 3b280ae to 49e2065 Compare March 2, 2023 21:02
@ptrus ptrus force-pushed the ptrus/feature/analzyer-stats-activeacc branch from 49e2065 to 1fd3e6e Compare March 2, 2023 21:04
@ptrus ptrus merged commit a05eb96 into main Mar 2, 2023
@ptrus ptrus deleted the ptrus/feature/analzyer-stats-activeacc branch March 2, 2023 21:47
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.

None yet

2 participants