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

Include request ID in REST API responses #11254

Closed
roberteriksen1979 opened this issue Dec 20, 2022 · 4 comments
Closed

Include request ID in REST API responses #11254

roberteriksen1979 opened this issue Dec 20, 2022 · 4 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@roberteriksen1979
Copy link

NetBox version

3.2.5

Feature type

Change to existing functionality

Proposed functionality

When changing an item, using the REST API, could it be possible to get the changelog id returned immediately?
f.x as an X-ChangeId header or similar?

Use case

When multiple systems update various properties of the same entities in Netbox, we can not always rely on simply getting the latest change via the extras/object-changes endpoint.
Also getting the change id immediately would save an otherwise unnecessary API request.

Database changes

No response

External dependencies

No response

@roberteriksen1979 roberteriksen1979 added the type: feature Introduction of new functionality to the application label Dec 20, 2022
@jeremystretch
Copy link
Member

When changing an item, using the REST API, could it be possible to get the changelog id returned immediately?

This could be feasible currently, however we need to consider future plans to generate changelog records outside of the request/response cycle (see #11202), which would inhibit us from returning the ObjectChange ID directly. (In this scenario, the ObjectChange would not be created until just after the response has been sent.) Additionally, bulk changes would result in the creation of multiple ObjectChanges, so we'd need a way to convey those.

Alternatively, we could attach to the API response the UUID of the request, which could then be used to query for all ObjectChange records relevant to the specific request.

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Dec 22, 2022
@jeremystretch
Copy link
Member

Alternatively, we could attach to the API response the UUID of the request, which could then be used to query for all ObjectChange records relevant to the specific request.

I'm going to move this to "needs milestone" with the assumption that this is the preferred approach. Many changes can result in the creation of multiple new change records, and conveying them reliably and succinctly would be difficult. Returning the unique request ID is a lot more portable.

@jeremystretch jeremystretch added needs milestone Awaiting prioritization for inclusion with a future NetBox release and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Jan 5, 2023
@jeremystretch jeremystretch changed the title Return changelog id on post/patch with REST API Include request ID in REST API responses Jan 5, 2023
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed needs milestone Awaiting prioritization for inclusion with a future NetBox release labels Jan 5, 2023
@jeremystretch jeremystretch added this to the v3.5 milestone Jan 5, 2023
@arthanson
Copy link
Collaborator

Note: This would be similar to a correlation ID in logging (which might also be useful) There are two Django packages that do this that could be used for inspiration https://github.com/snok/django-guid and https://github.com/Polyconseil/django-cid

@tyler-8
Copy link
Contributor

tyler-8 commented Jan 12, 2023

Just to add - I think it makes sense for the request UUID to be returned as part of the response headers, rather than the payload itself. In other APIs where similar type of data is returned, headers seem to be the common pattern.

@jeremystretch jeremystretch self-assigned this Jan 13, 2023
jeremystretch added a commit that referenced this issue Jan 13, 2023
… unique ID of each request for change logging
jeremystretch added a commit that referenced this issue Feb 20, 2023
… unique ID of each request for change logging
jeremystretch added a commit that referenced this issue Feb 20, 2023
… unique ID of each request for change logging
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

4 participants