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

fix(request-id): we can use different ids with the same request #4479

Merged
merged 10 commits into from
Jun 30, 2021
Merged

fix(request-id): we can use different ids with the same request #4479

merged 10 commits into from
Jun 30, 2021

Conversation

zuiyangqingzhou
Copy link
Contributor

What this PR does / why we need it:

fix: 4460

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@tzssangglass
Copy link
Member

@zuiyangqingzhou hi, need to add test cases

@@ -49,7 +49,7 @@ function _M.rewrite(conf, ctx)
end

if conf.include_in_response then
ctx.x_request_id = uuid_val
ctx[conf.header_name] = uuid_val
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to add a prefix like request-id as conf.header_name may override other value by accident.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree +1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don’t really understand the intention of adding a prefix, because header_name is originally defined by the user. He should know what the definition of header_name looks like.

Copy link
Member

Choose a reason for hiding this comment

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

But he doesn't know all the fields in the ctx and the field will be added to ctx in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean like this?

if conf.include_in_response then
        ctx["request-id" .. conf.header_name] = uuid_val
end

Copy link
Member

Choose a reason for hiding this comment

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

ctx["request-id-" .. conf.header_name] = uuid_val would be better.

Copy link
Contributor Author

@zuiyangqingzhou zuiyangqingzhou Jun 25, 2021

Choose a reason for hiding this comment

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

All right!

In addition, I found that unit testing is not easy to do. Is there any related documentation?

Thank you

Copy link
Member

Choose a reason for hiding this comment

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

You can configure global rule and route like this one, with /echo uri:

=== TEST 15: empty global rule

function _M.echo()

And then hit it and check the header sent to upstream via :

apisix/t/plugin/zipkin.t

Lines 458 to 462 in b76f20e

=== TEST 15: set x-b3-sampled if sampled
--- request
GET /echo
--- response_headers
x-b3-sampled: 1

}
})

if res.headers["X-Request-Id"] and res.headers["Custom-Header-Name"] and res.headers["X-Request-Id"] ~= res.headers["Custom-Header-Name"] then
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not verify these two values when they are present, actually they must present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, got it

})

if res.headers["X-Request-Id"] and res.headers["Custom-Header-Name"] and res.headers["X-Request-Id"] ~= res.headers["Custom-Header-Name"] then
ngx.say("X-Request-Id and Custom-Header-Name is different")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ngx.say("X-Request-Id and Custom-Header-Name is different")
ngx.say("X-Request-Id and Custom-Header-Name are different")

--- response_body
passed
--- no_error_log
[error]
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

there should be 3 blank lines between test cases, or you can use the reindex to do. the CI error is about this.

@zuiyangqingzhou
Copy link
Contributor Author

@spacewander
Copy link
Member

Don't be afraid, known issue: #4503

@spacewander spacewander changed the title fix: Multiple request-id bug fix(request-id): we can use different request-id with the same request Jun 30, 2021
@spacewander spacewander changed the title fix(request-id): we can use different request-id with the same request fix(request-id): we can use different ids with the same request Jun 30, 2021
@spacewander spacewander merged commit 756fad1 into apache:master Jun 30, 2021
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.

bug: The request-id plugin may have a bug
4 participants