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

Add correlation id middleware #82

Merged
merged 3 commits into from
Sep 24, 2019
Merged

Add correlation id middleware #82

merged 3 commits into from
Sep 24, 2019

Conversation

ataleksandrov
Copy link
Contributor

Fixes #81.

Added:

  • Correlation id middleware

Pull request:

  • implementation
  • tests

@cf-gitbot
Copy link
Member

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/168536968

The labels on this github issue will be updated when the story is started.

@winnab
Copy link
Contributor

winnab commented Sep 17, 2019

Hello @ataleksandrov! Thanks for the PR. The first thing we want to clarify is that the brokerapi project aims to be OSBAPI compliant, and we think the request header property X-Broker-API-Request-Identity is the OSBAPI way to achieve what you're after. Is there a reason you went with correlation ID instead of X-Broker-API-Request-Identity?

@ataleksandrov
Copy link
Contributor Author

Hello @winnab! I went with correlation id because I need an id that is unique to a transaction, which can span multiple requests ( e.g. async provision ). The way I understand the X-Broker-API-Request-Identity header ( and how it is implemented in the cloud controller for example ) is that it's a unique id for every request, not for a transaction. I use a correlation id as a transaction id. The correlation id must be provided by the client ( e.g. the cloud controller ) and it must be the same for every request made in the transaction. Even though it is not in the specification, I think there should be such a header that carries that meaning and I have chosen the correlation id, because it is a common HTTP header.

@winnab
Copy link
Contributor

winnab commented Sep 18, 2019

Great. Thanks @ataleksandrov! Our team will review and get back to you as soon as we can.


const CorrelationIDKey = "correlation-id"

var correlationIDHeaders = []string{"X-Correlation-ID", "X-CorrelationID", "X-ForRequest-ID", "X-Request-ID", "X-Vcap-Request-Id"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to verify all of these headers? If so, could you add tests for the missing ones (a table test or a for loop would do it)?

Do we care if more than one is passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are absolutely right, there should be tests for each header. About the other question I don't think there should ever be more than one header, that carries such meaning for a request. But if somehow there is more than one header this indicates an integration problem between system components. We check more than one header because different systems can set the correlation id in different headers and these are the ones that are commonly used. The first one we find will be read, the rest will be ignored.

}

w.Header().Set(headerName, correlationID)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The correlation id header should not be set to the response.

Gopkg.lock Outdated
@@ -22,6 +22,14 @@
revision = "ab2d9a74b97eda058004c8deef80ac624432f408"
version = "v1.0.0"

[[projects]]
digest = "1:141cc9fc6279592458b304038bd16a05ef477d125c6dad281216345a11746fd7"
name = "github.com/gofrs/uuid"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @ataleksandrov! Sorry, we just noticed you added a new UUID generation dependency. We are already using https://github.com/pborman/uuid in this project. Do you have a strong objection to using the package we already have? If not, could you update your code to use the pborman dependency? If you do want to use this new package, could you swap out the pborman package where we use it for this one to minimise dependencies and make sure to update the Gopkg.toml?

@FelisiaM FelisiaM merged commit 970c084 into pivotal-cf:master Sep 24, 2019
@FelisiaM
Copy link
Contributor

Hi @ataleksandrov!

We have now merged this PR :)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enrich request context with correlation id
4 participants