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

feat: add support for listing account activity #233

Merged
merged 4 commits into from
Apr 18, 2024

Conversation

tjhop
Copy link
Contributor

@tjhop tjhop commented Apr 4, 2024

This adds a new service to enable listing NS1 account activity. The endpoint supports many url parameters to adjust response behavior (such as changing/limiting how many activity entries are returned, etc), but for this initial approach, the sdk just uses the endpoint directly with the endpoint's normal default values.

I used a small Terraform config to generate 50 dummy DNS records on my NS1 account to generate some account activity and have confirmed that the endpoint operates as expected -- the values I expected are returned, the response is limited to the last 20 activity entries like the endpoint default, etc.

This adds a new service to enable listing NS1 account activity. The
endpoint supports many url parameters to adjust response behavior (such
as changing/limiting how many activity entries are returned, etc), but
for this initial approach, the sdk just uses the endpoint directly with
the endpoint's normal default values.

I used a small Terraform config to generate 50 dummy DNS records on my
NS1 account to generate some account activity and have confirmed that
the endpoint operates as expected -- the values I expected are returned,
the response is limited to the last 20 activity entries like the
endpoint default, etc.

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
@tjhop tjhop force-pushed the feat/account-activity-support branch from de40e55 to 5ed1f9e Compare April 4, 2024 14:20
tjhop added a commit to tjhop/ns1-go that referenced this pull request Apr 4, 2024
Several NS1 API endpoints allow setting URL parameters to alter the
behavior of the endpoint. For instance, a `limit` parameter can be set
on the `/account/activity` endpoint to control how many events are
returned in the response. This would be useful in ns1#233.

This commit adds support for URL parameters by adding a new struct
`Param` to the `rest` package, and updating `rest.client.Do()` and
`rest.client.DoWithPagination()` to accept a variable amount of params.
In order for higher level services based off of the common service to
set url params, they will need to pass them through when invoking the
client's `Do()` method, like so:

```golang
resp, err := s.client.Do(req, &al, params...)
```
Depends on ns1#234

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
Depends on ns1#234

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
@tjhop tjhop force-pushed the feat/account-activity-support branch from 44b1617 to 3f841e0 Compare April 4, 2024 19:24
Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
@bduggan-ns1 bduggan-ns1 merged commit b1f0b3a into ns1:v2 Apr 18, 2024
3 checks passed
tjhop added a commit to tjhop/ns1_exporter that referenced this pull request Apr 25, 2024
I added support to ns1-go to list account activity upstream:
ns1/ns1-go#233

This adds support for utilizing this endpoint for more efficient service
discovery updates.

It uses a similar refresh mechanism to what I used when working on linode
service discovery for prometheus:
https://github.com/prometheus/prometheus/blob/76b0318ed52e655e96a3a4734e3678bf55801616/discovery/linode/linode.go#L183-L231

Rather than refreshing all zone/record cache on every refresh interval,
the SD mechanism will now poll the `/account/activity` endpoint. If
activity is detected that could affect the zone/record data used to
create SD targets, then the SD mechanism will actually go ahead and
refresh it's cache. There's a max of 10 polls with no activity detected
before refreshing cache regardless of activity status, to ensure that
cache is valid/recent.
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.

3 participants