Skip to content

Instantly share code, notes, and snippets.

@thrawn01
Last active January 30, 2019 17:40
Show Gist options
  • Save thrawn01/aa4262b1aa1dc82b41c34b22fd596805 to your computer and use it in GitHub Desktop.
Save thrawn01/aa4262b1aa1dc82b41c34b22fd596805 to your computer and use it in GitHub Desktop.
Account Stats API Proposal

Account Totals by Domain


This API allows customers to retrieve a single count for a every domain in their account. This allows customers to identify domains based on a stat. (IE: Most active, Most Bounces, etc..)

GET /accounts/totals
Parameter Description
event Name of the event to retrieve stats for; can repeat
timestamp The timestamp you wish to retrieve stats for (Format is 'Mon, 26 Jan 2018 17:00:00 UTC')
resolution The resolution you wish to retrieve (Valid options are 'hour', 'day' , 'month')
GET http://api.mailgun.net/v3/account/totals?event=accepted
Response Body
{
    "resolution": "day",
    "stats":{
        "mg.example.com":[
            {
                "time": "Tue, 22 Jan 2019 00:00:00 UTC",
                "accepted":{"incoming": 0, "outgoing": 0, "total": 0}
            }
        ]
    },
    "timestamp": "Tue, 22 Jan 2019 00:00:00 UTC"
}

Implementation

The service that implements this call will have to perform the following

  1. Given the account id provided by flagman header X-Account-ID make a call to the registry server to retrieve a list of domain names and ids for this account.
  2. Make a call for each domain id to a data provider to retrieve stats for each individual domain by id.
  3. Compile the results into a JSON payload, resolving domain id's back to names before returning the result.

Notes: Step 2 should be performed by sending requests for each domain simultaneously and asynchronously waiting for responses. If the service is talking with scout, or is talking directly with cassandra this is the most effecient and performant method.

Comments

  • (thrawn01) Putting this API in scout is not presupposed, it can as easily and performantly be implemented in another service, provided the other service can make simultaneous async calls to scout. However, I leave that decision to the analytics team, as they will need to deal with scouts additional dependency on the registry service.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment