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

correlation-id plugin, fixes #1086 #1094

Closed
wants to merge 4 commits into from
Closed

Conversation

opyate
Copy link
Contributor

@opyate opyate commented Mar 22, 2016

No description provided.

end

-- For later use, to echo it back downstream
ngx.ctx.correlationid_header_value = header_value
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure this feature benefits the plugin. I would expect such a behavior to be quite private and only related to the internals of one's infrastructure. I would be in favor of making this behavior configurable, and disabled by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Echoing back downstream?
Sure it will - it will help the caller "correlate" if there was a problem with the request.
E.g. mockbin also echos x-request-id back:

curl http://mockbin.com/request --data 'foo=bar'

{
  "startedDateTime": "2016-03-22T19:42:26.954Z",
  "clientIPAddress": "77.101.29.24",
  "method": "POST",
  "url": "http://mockbin.com/request",
  "httpVersion": "HTTP/1.1",
  "cookies": {},
  "headers": {
    "host": "mockbin.com",
    "connection": "close",
    "accept-encoding": "gzip",
    "x-forwarded-for": "77.101.29.24, 162.158.152.161",
    "cf-ray": "287c2079a0a73578-LHR",
    "x-forwarded-proto": "http",
    "cf-visitor": "{\"scheme\":\"http\"}",
    "user-agent": "curl/7.47.1",
    "accept": "*/*",
    "x-request-id": "b04bad2e-c240-43ad-a0f9-60c98d86599d",
    "content-type": "application/x-www-form-urlencoded",
    "cf-connecting-ip": "77.101.29.24",
    "x-forwarded-port": "80",
    "via": "1.1 vegur",
    "connect-time": "0",
    "x-request-start": "1458675746943",
    "total-route-time": "0",
    "content-length": "7"
  },
  "queryString": {},
  "postData": {
    "mimeType": "application/x-www-form-urlencoded",
    "text": "foo=bar",
    "params": {
      "foo": "bar"
    }
  },
  "headersSize": 535,
  "bodySize": 7
}

Please confirm if you disagree, then I'll make it configurable.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it could help for sure, but I think most providers do not want to expose their internals to the public facing side of their services, is what I meant :)

Copy link
Member

Choose a reason for hiding this comment

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

(mockbin echoes it back because it simply echoes whatever you send to it)

@thibaultcha
Copy link
Member

Hey, that looks great! Just added a few concerns. Thanks :)

@thibaultcha thibaultcha added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Mar 22, 2016
@coveralls
Copy link

Coverage Status

Coverage remained the same at 59.451% when pulling ed761a5edb618dbfda37a76c696b26cb81b34107 on opyate:correlation-id into c9d3e56 on Mashape:next.

@thibaultcha
Copy link
Member

The linting fails with 2 errors:

$ make lint
Checking kong/plugins/oauth2/api.lua              1 warning
    kong/plugins/oauth2/api.lua:2:7: unused variable utils
Checking spec/plugins/oauth2/access_spec.lua      1 warning
    spec/plugins/oauth2/access_spec.lua:304:33: unused variable headers
Total: 2 warnings / 0 errors in 274 files

@opyate
Copy link
Contributor Author

opyate commented Mar 22, 2016

Not my code :)

@thibaultcha
Copy link
Member

Oh indeed! I'm sorry haha, I should have checked! (not sure how it went through, I assumed that was not possible...)

@ahmadnassri
Copy link
Contributor

yes, mockbin does its own x-request-id :)

@opyate
Copy link
Contributor Author

opyate commented Mar 22, 2016

I committed the spec matcher, but since rebasing this error popped up which means I don't know if my commit will work.

./spec/spec_helpers.lua:222: Error during migration 2016-03-07-jwt-alg: [Invalid] Invalid column name algorithm because it conflicts with an existing column

@thibaultcha
Copy link
Member

yes, mockbin does its own x-request-id :)

Fair enough! But mockbin is a debugging/development tool :) I think we can all agree on why this should not be the default behavior for our use case.

@opyate
Copy link
Contributor Author

opyate commented Mar 22, 2016

OK, I'll make "echo correlation ID back to downstream" configurable.
Thanks for all the suggestions thus far!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 59.451% when pulling d612dc031b2e8402297b251624ec656136e32263 on opyate:correlation-id into c9d3e56 on Mashape:next.

@thibaultcha
Copy link
Member

./spec/spec_helpers.lua:222: Error during migration 2016-03-07-jwt-alg: [Invalid] Invalid column name algorithm because it conflicts with an existing column

Fixing this is easy: delete all keyspaces in your Cassandra cluster (kong_development, kong, kong_tests) and make sure to be up-to-date with next.

@opyate
Copy link
Contributor Author

opyate commented Mar 22, 2016

sudo make clean and sudo make dev tripped up on JWT again, so I deleted all traces of it (temporarily for testing purposes), but now there's a new problem:

[----------] Running tests from spec/plugins/correlation-id/access_spec.lua
./kong/tools/faker.lua:87: Faker failed to insert api entity: upstream_url=http://mockbin.com request_host=correlation1.com
[Invalid] unconfigured columnfamily apis

stack traceback:
        ./kong/tools/faker.lua:87: in function 'insert_fixtures'
        spec/plugins/correlation-id/access_spec.lua:14: in function <spec/plugins/correlation-id/access_spec.lua:12>

./spec/spec_helpers.lua:75: spec_helper cannot stop kong: 
[INFO] Using configuration: kong_TEST.yml[ERR] Kong is not running

stack traceback:
        ./spec/spec_helpers.lua:75: in function 'stop_kong'
        spec/plugins/correlation-id/access_spec.lua:30: in function <spec/plugins/correlation-id/access_spec.lua:29>

[----------] 0 tests from spec/plugins/correlation-id/access_spec.lua (1014.09 ms total)

@ahmadnassri
Copy link
Contributor

Fair enough! But mockbin is a debugging/development tool :) I think we can all agree on why this should not be the default behavior for our use case.

agreed, and mockbin should also not override such headers if they exist: Kong/insomnia-mockbin#45

@opyate
Copy link
Contributor Author

opyate commented Mar 22, 2016

Silly me: json.decode(response).headers aren't the real headers, but a mockbin -specific thing.

I'll change the spec to test for actual headers, but perhaps @thibaultcha can look at the Cassandra-related problem that's blocking my testing since the rebase (yes, I have the latest next).

@thibaultcha
Copy link
Member

@opyate Seems your migrations did not run correctly for some reason.

@opyate
Copy link
Contributor Author

opyate commented Mar 23, 2016

@thibaultcha I've committed the following:

  • changed tests to test actual headers, not mockbin-response-headers
  • added extra test for the case where downstream doesn't echo the correlation header
  • reverted the busted:match stuff - I don't think it does patterns ;)

Also, following the keyspace mess from yesterday, I think the Makefile clean section can benefit from something like this:

TMPDK=$(mktemp -t kongXXXXXX) && echo -e "drop keyspace kong_tests;\ndrop keyspace kong_development;" > $TMPDK && cassandra-cli -f $TMPDK && rm $TMPDK

@coveralls
Copy link

Coverage Status

Coverage remained the same at 59.467% when pulling 4e12036 on opyate:correlation-id into efff148 on Mashape:next.

@thibaultcha
Copy link
Member

Yes it does patterns, I have used it numerous times. See the luassert code base if doubts persist.

The make clean command is intended to be run without the datastores running. Anyways, such "messes" as you say are rare and would only occur during development, as migrations aren't always fixed until releasing. That is fine.

On Mar 23, 2016, at 12:55 AM, Juan M Uys [email protected] wrote:

@thibaultcha I've committed the following:

changed tests to test actual headers, not mockbin-response-headers
added extra test for the case where downstream doesn't echo the correlation header
reverted the busted:match stuff - I don't think it does patterns ;)
Also, following the keyspace mess from yesterday, I think the Makefile clean section can benefit from something like this:

TMPDK=$(mktemp -t kongXXXXXX) && echo -e "drop keyspace kong_tests;\ndrop keyspace kong_development;" > $TMPDK && cassandra-cli -f $TMPDK && rm $TMPDK

You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@thibaultcha
Copy link
Member

Heh, it seems clean is already using the migrations. Mixing with other projects... But the issue here is that one is free to have as many keyspaces as desired (even for testing, I often use several ones) and thus the command can never know which ones are in an inconsistent state. Plus deleting other keyspaces, even developement is very unsafe and might not always be desired. Only the tests keyspace should be deleted without too much worrying.
In fact I'm not even such a fan of having clean doing this job. Will probably change to reflect the behavior of said projects.

@opyate
Copy link
Contributor Author

opyate commented Mar 23, 2016

See the luassert code base if doubts persist.

@thibaultcha Found it - apologies for doubting you :)

This should be it!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 59.467% when pulling 52756e9 on opyate:correlation-id into efff148 on Mashape:next.

@thibaultcha
Copy link
Member

Hey,

I agree that this looks ready! A couple last things:

  • Would you please write some documentation for your plugin at https://github.com/Mashape/getkong.org? Thanks!
  • Could you squash your commits into 1, and maybe rebase on next? If you don't want to go through the troubles, I'll do it when applying the patch, no worries.
  • And finally: is everybody satisfied with this plugin name? I am asking since as of today, it is very difficult to change the name of an existing (shipped) plugin, so let's be sure it is clear to everyone. I agree that the current name makes perfect sense, but maybe users would search for such a feature under a different name, such as "request-id"? Just bringing the point to make sure correlation-id makes sense for everyone :)


assert.are_not_equals(correlation_id1, correlation_id2)

-- TODO kong_TEST.yml's worker_processes has to be 1 for the below to work.
Copy link
Member

Choose a reason for hiding this comment

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

It will be in the future :)

@Tieske
Copy link
Member

Tieske commented Mar 25, 2016

how about "request-tracker"?

@sonicaghi
Copy link
Member

Requests Trace

@jl91
Copy link

jl91 commented Mar 31, 2016

a similar problem here #1118

@subnetmarco
Copy link
Member

What is the status of this PR?

@opyate
Copy link
Contributor Author

opyate commented Apr 6, 2016

What is the status of this PR?

As the commiter, here's my opinion:

@codebien
Copy link

codebien commented Apr 6, 2016

IMHO "Web people" know this feature as Request-ID.

@opyate
Copy link
Contributor Author

opyate commented Apr 6, 2016

Tried to rebase to latest next, and now

stat: cannot stat `kong/api/route_helpers.lua': No such file or directory

Error: Build error: Failed installing kong/api/route_helpers.lua in /usr/local/lib/luarocks/rocks/kong/0.7.0-0/lua/kong/api/route_helpers.lua
make: *** [install] Error 1

@thibaultcha
Copy link
Member

Hey @opyate, no worries, I have manually merged this to git next!

  • Squashed your patch
  • Slightly tweaked the tests to check for headers received by upstream as well
  • Added the new plugin to the unreleased changelogs.

Thanks a lot for contributing on this!

@thibaultcha thibaultcha removed the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Apr 11, 2016
@thibaultcha
Copy link
Member

PS: correlation-id will do it for a name. It is, after all, the technical term for such a feature :)
PPS: we'll try to get this included in the 0.8 release

@opyate
Copy link
Contributor Author

opyate commented Apr 12, 2016

Thanks a lot for contributing on this!

Thanks for all the assistance!

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.

9 participants