Skip to content

Conversation

@rob05c
Copy link
Member

@rob05c rob05c commented May 6, 2022

Fixes core strategies and parent_select plugin scheme to be optional, and adds a test.

Backstory: some time ago I noticed the strategies.yaml scheme was optional, and a strategy without a scheme would match a host without a scheme. This behavior seemed to be incidental, but it made it much easier for me to generate config, it would have been difficult to get the scheme in the parent generation, all that logic lived in a separate area of our code for remap generation. And the "scheme" isn't actually used by the strategy for anything except matching hosts; the actual scheme used for upstream requests is always the remap target scheme.

So I documented the behavior:
https://docs.trafficserver.apache.org/en/latest/admin-guide/files/strategies.yaml.en.html

scheme: Indicates which scheme the strategy supports, http or https. Note this is only used to match hosts to strategies; the actual scheme used in the upstream request will be the scheme of the remap.config target, regardless of this value. The scheme is optional, and strategies without a scheme will match hosts without a scheme. This allows for omitting the scheme if hosts are not shared between strategies, or if all strategies using a given host use the same scheme.

This was broken recently, and changed to reject strategies.yaml files without schemes (as part of a larger validation PR). Which broke all our generated strategies.yaml files.

This PR fixes it to match the docs, and adds an autest to ensure it doesn't break again, and also comments in the code to make the intent clear.

@rob05c rob05c requested a review from bryancall as a code owner May 6, 2022 19:58
@randall randall added this to the 10.0.0 milestone May 9, 2022
@rob05c rob05c added the 9.2.0 label May 9, 2022
@rob05c rob05c modified the milestones: 10.0.0, 9.2.0 May 9, 2022
@bryancall bryancall requested a review from ywkaras May 9, 2022 23:03
scheme = PL_NH_SCHEME_NONE;
PL_NH_Note("Invalid 'scheme' value, '%s', for the strategy named '%s', setting to PL_NH_SCHEME_NONE", scheme_val.c_str(),
strategy_name.c_str());
PL_NH_Note("Invalid scheme '%s' for strategy '%s', setting to NONE", scheme_val.c_str(), strategy_name.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this isn't a constructor, seem slightly fragile to assume data member contain values set at construction. Hopefully no one ever assumes this function can re-init as well as init.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't write the func, it's inherited from core. But it has to exist because the object is constructed by the YAML library.

I think Init is effectively like a constructor, because we can't construct, since we can't prevent the YAML library from doing the construction.

But, I think Init does make that assumption. There are probably other data it doesn't reset either. I don't object to making Init safe in case someone re-init's an object, and resetting all members to their defaults, but that's probably a larger change and might be better as its own PR

nh.scheme = PL_NH_SCHEME_HTTPS;
} else {
throw YAML::ParserException(node["scheme"].Mark(), "no valid scheme defined, valid schemes are http or https");
PL_NH_Note("Invalid scheme '%s' for protocol, setting to NONE", scheme_val.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@randall randall modified the milestones: 9.2.0, 10.0.0 May 10, 2022
@rob05c rob05c merged commit 695f9f6 into apache:master May 16, 2022
zwoop pushed a commit that referenced this pull request May 16, 2022
@zwoop
Copy link
Contributor

zwoop commented May 16, 2022

Cherry-picked to v9.2.x

@zwoop zwoop modified the milestones: 10.0.0, 9.2.0 May 16, 2022
masaori335 pushed a commit to masaori335/trafficserver that referenced this pull request Feb 21, 2023
* asf/9.2.x:
  Updated ChangeLog
  Fix parent_select optional scheme (apache#8831)
  Add `#pragma once` for PendingAction.h (apache#8846)
  Promote class PendingAction from HttpSM.h for use in other classes. (apache#8423)
  Fixes leak in SNIAction name globbing (apache#8827)
  Handle opentelemetry-cpp v1.3.0 upgrade for otel_tracer plugin (apache#8834)
  Fix overflow conditions in prefetch plugin (apache#8660)
  Remove incorrect comment from base64 functions (apache#8835)
  Add autest to cover updates to cache with alternates (apache#8779)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants