Skip to content

[header map] remove integer setter for string headers#14773

Merged
asraa merged 3 commits intoenvoyproxy:mainfrom
asraa:remove-extra-int-sets
Jan 29, 2021
Merged

[header map] remove integer setter for string headers#14773
asraa merged 3 commits intoenvoyproxy:mainfrom
asraa:remove-extra-int-sets

Conversation

@asraa
Copy link
Contributor

@asraa asraa commented Jan 20, 2021

Signed-off-by: Asra Ali asraa@google.com

Commit Message: Splits string/numeric header values so that set##name(int val) is only generated for integer headers and append##name(string), setReference##name(string) are only generated for header fields that use strings.

Additional Description:

  • 63 functions removed. (Removes 2 string methods from 8 numerical headers, and 1 numerical method from 47 headers)

QUESTION:

  • Is there even a reason to have an integer setter in the future? There are more uses of response_headers>setStatus(std::to_string(enumToInt(Code::OK))); than response_headers->setStatus(integer), partly because sometimes the status is set with a value like headers->setStatus(other->getStatusValue()). If so, that would simplify the macros.`

Risk Level: Med, touches a lot of code, but should not be that scary.
Testing: Tests pass
Fixes: #8567

asraa added 2 commits January 20, 2021 14:42
Signed-off-by: Asra Ali <asraa@google.com>
Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

lgtm modulo some very minor nits. Thanks for doing this.


#define DEFINE_INLINE_HEADER_NUMERIC_FUNCS(name) \
DEFINE_INLINE_HEADER_FUNCS(name) \
void set##name(uint64_t value) override { setInline(HeaderHandles::get().name, value); }
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no integer getter. Should there be?

Copy link
Contributor Author

@asraa asraa Jan 22, 2021

Choose a reason for hiding this comment

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

There never was before -- an integer getter would help in the case I mentioned in the description, but I think it's strictly worse to have.
response_headers>setStatus(other->getStatusValue());

Changing it to
response_headers>setStatus(other->getStatusInt());
would mean there'd be a (string -> int -> string) conversion, compared to the no conversion above.

Signed-off-by: Asra Ali <asraa@google.com>
Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

RE copying values by converting to/from ints: that makes sense; better to leave as string. I thought it might, though remove redundant code to do the conversion at call-sites, but maybe it's not worth it since it's basically one call to whatever the latest wrapper around strtoll is.

@jmarantz
Copy link
Contributor

@envoyproxy/senior-maintainers

@asraa
Copy link
Contributor Author

asraa commented Jan 29, 2021

ping @envoyproxy/senior-maintainers
This change isn't functional, basically removes 63 unused methods in headermap

Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Just one question, otherwise LGTM

Comment on lines -472 to -479
{
// Set and then append. This mimics how GrpcTimeout is set.
TestRequestHeaderMapImpl headers;
headers.setGrpcTimeout(42);
EXPECT_EQ(headers.getGrpcTimeoutValue(), "42");
headers.appendGrpcTimeout("s", "");
EXPECT_EQ(headers.getGrpcTimeoutValue(), "42s");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove this? Is this covered by another test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it's behavior is covered by Via:

// Create via header and append.

It was meant to test how grpc-timeout is specifically set here

headers.setGrpcTimeout(absl::StrCat(time, absl::string_view(unit, 1)));
, but that's not how grpc-timeout is set anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining!

Comment on lines -472 to -479
{
// Set and then append. This mimics how GrpcTimeout is set.
TestRequestHeaderMapImpl headers;
headers.setGrpcTimeout(42);
EXPECT_EQ(headers.getGrpcTimeoutValue(), "42");
headers.appendGrpcTimeout("s", "");
EXPECT_EQ(headers.getGrpcTimeoutValue(), "42s");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining!

@asraa asraa merged commit 4dbcb63 into envoyproxy:main Jan 29, 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.

[HeaderMap] Eliminate non-const header access functions follow-up

3 participants