This is an automated email from the ASF dual-hosted git repository.
rob pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 96d7e3e0e8 Add t3c support for __CACHEKEY_DIRECTIVE__ in raw remap
text (#6978)
96d7e3e0e8 is described below
commit 96d7e3e0e8aa76e939bf5253cd8622aa5b1484d9
Author: Brian Olsen <[email protected]>
AuthorDate: Thu Jul 21 14:12:56 2022 -0600
Add t3c support for __CACHEKEY_DIRECTIVE__ in raw remap text (#6978)
---
CHANGELOG.md | 1 +
docs/source/overview/delivery_services.rst | 2 +
lib/go-atscfg/remapdotconfig.go | 22 +++--
lib/go-atscfg/remapdotconfig_test.go | 133 +++++++++++++++++++++++++++++
4 files changed, 152 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 286df2dca6..253641f88f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -598,6 +598,7 @@ will be returned indicating that overlap exists.
- Changed Traffic Portal to use the more performant and powerful ag-grid for
the delivery service request (DSR) table.
- Traffic Ops: removed change log entry created during server
update/revalidation unqueue
- Updated CDN in a Box to CentOS 8 and added `RHEL_VERSION` Docker build arg
so CDN in a Box can be built for CentOS 7, if desired
+- Added Delivery Service Raw Remap `__CACHEKEY_DIRECTIVE__` directive to allow
inserting the cachekey directive into the Raw Remap text. This allows Raw
Remaps which manipulate the cachekey.
### Deprecated
- Deprecated the non-nullable `DeliveryService` Go struct and other structs
that use it. `DeliveryServiceNullable` structs should be used instead.
diff --git a/docs/source/overview/delivery_services.rst
b/docs/source/overview/delivery_services.rst
index 8c7932fa12..811da8d1b4 100644
--- a/docs/source/overview/delivery_services.rst
+++ b/docs/source/overview/delivery_services.rst
@@ -679,6 +679,8 @@ The Raw Remap text is ordinarily added at the end of the
line, after everything
For example, if you have an Apache Traffic Server lua plugin which manipulates
the range, and are using Slice Range Request Handling which needs to run after
your plugin, you can set a Raw Remap, ``@plugin=tslua.so @pparam=range.lua
__RANGE_DIRECTIVE__``, and the ``@plugin=slice.so`` range directive will be
inserted after your plugin.
+Similarly the text ``__CACHEKEY_DIRECTIVE__`` can be moved into the Raw Remap
text to allow the Raw Remap text to manipulate the uri contents before the
cachekey is generated.
+
.. _ds-regex-remap:
Regex Remap Expression
diff --git a/lib/go-atscfg/remapdotconfig.go b/lib/go-atscfg/remapdotconfig.go
index b0201ea687..bf7aab24bd 100644
--- a/lib/go-atscfg/remapdotconfig.go
+++ b/lib/go-atscfg/remapdotconfig.go
@@ -36,6 +36,7 @@ const ContentTypeRemapDotConfig = ContentTypeTextASCII
const LineCommentRemapDotConfig = LineCommentHash
const RemapConfigRangeDirective = `__RANGE_DIRECTIVE__`
+const RemapConfigCachekeyDirective = `__CACHEKEY_DIRECTIVE__`
// RemapDotConfigOpts contains settings to configure generation options.
type RemapDotConfigOpts struct {
@@ -557,8 +558,15 @@ func buildEdgeRemapLine(
}
}
+ // This allows the Range and Cachekey directive hacks
+ remapText := ""
+ if ds.RemapText != nil {
+ remapText = *ds.RemapText
+ }
+
// Form the cachekey args string, qstring ignore, then
// remap.config then cachekey.config
+ cachekeyTxt := ""
cachekeyArgs := ""
if ds.QStringIgnore != nil {
@@ -575,7 +583,14 @@ func buildEdgeRemapLine(
}
if cachekeyArgs != "" {
- text += " @plugin=cachekey.so" + cachekeyArgs
+ cachekeyTxt = " @plugin=cachekey.so" + cachekeyArgs
+ }
+
+ // Temporary hack for moving the cachekey directive into the raw remap
text
+ if strings.Contains(remapText, RemapConfigCachekeyDirective) {
+ remapText = strings.Replace(remapText,
RemapConfigCachekeyDirective, cachekeyTxt, 1)
+ } else {
+ text += cachekeyTxt
}
// Note: should use full path here?
@@ -605,11 +620,6 @@ func buildEdgeRemapLine(
}
}
- remapText := ""
- if ds.RemapText != nil {
- remapText = *ds.RemapText
- }
-
// Temporary hack for moving the range directive into the raw remap text
if strings.Contains(remapText, RemapConfigRangeDirective) {
remapText = strings.Replace(remapText,
RemapConfigRangeDirective, rangeReqTxt, 1)
diff --git a/lib/go-atscfg/remapdotconfig_test.go
b/lib/go-atscfg/remapdotconfig_test.go
index 8752f8560b..20bfa4fe0c 100644
--- a/lib/go-atscfg/remapdotconfig_test.go
+++ b/lib/go-atscfg/remapdotconfig_test.go
@@ -5726,6 +5726,139 @@ func TestMakeRemapDotConfigRawRemapRangeDirective(t
*testing.T) {
}
}
+func TestMakeRemapDotConfigRawRemapCachekeyDirective(t *testing.T) {
+ hdr := "myHeaderComment"
+
+ server := makeTestRemapServer()
+ server.Type = "EDGE"
+
+ ds := DeliveryService{}
+ ds.ID = util.IntPtr(48)
+ dsType := tc.DSType("HTTP_LIVE_NATNL")
+ ds.Type = &dsType
+ ds.OrgServerFQDN = util.StrPtr("origin.example.test")
+ ds.MidHeaderRewrite = util.StrPtr("")
+ ds.RemapText = util.StrPtr("@plugin=tslua.so
@pparam=uri-manipulator.lua __CACHEKEY_DIRECTIVE__")
+ ds.EdgeHeaderRewrite = nil
+ ds.SigningAlgorithm = util.StrPtr("foo")
+ ds.XMLID = util.StrPtr("mydsname")
+ ds.QStringIgnore =
util.IntPtr(int(tc.QueryStringIgnoreIgnoreInCacheKeyAndPassUp))
+ ds.RegexRemap = util.StrPtr("")
+ ds.FQPacingRate = util.IntPtr(0)
+ ds.DSCP = util.IntPtr(0)
+ ds.RoutingName = util.StrPtr("myroutingname")
+ ds.MultiSiteOrigin = util.BoolPtr(false)
+ ds.OriginShield = util.StrPtr("myoriginshield")
+ ds.ProfileID = util.IntPtr(49)
+ ds.ProfileName = util.StrPtr("dsprofile")
+ ds.Protocol = util.IntPtr(int(tc.DSProtocolHTTPAndHTTPS))
+ ds.AnonymousBlockingEnabled = util.BoolPtr(false)
+ ds.Active = util.BoolPtr(true)
+ ds.RangeSliceBlockSize = util.IntPtr(262144)
+
+ dses := []DeliveryService{ds}
+
+ dss := []DeliveryServiceServer{
+ DeliveryServiceServer{
+ Server: *server.ID,
+ DeliveryService: *ds.ID,
+ },
+ }
+
+ dsRegexes := []tc.DeliveryServiceRegexes{
+ tc.DeliveryServiceRegexes{
+ DSName: *ds.XMLID,
+ Regexes: []tc.DeliveryServiceRegex{
+ tc.DeliveryServiceRegex{
+ Type:
string(tc.DSMatchTypeHostRegex),
+ SetNumber: 0,
+ Pattern:
`myliteralpattern__http__foo`,
+ },
+ },
+ },
+ }
+
+ serverParams := []tc.Parameter{
+ tc.Parameter{
+ Name: "trafficserver",
+ ConfigFile: "package",
+ Value: "7",
+ Profiles: []byte(`["global"]`),
+ },
+ tc.Parameter{
+ Name: "serverpkgval",
+ ConfigFile: "package",
+ Value: "serverpkgval __HOSTNAME__ foo",
+ Profiles: []byte(server.ProfileNames[0]),
+ },
+ tc.Parameter{
+ Name: "dscp_remap_no",
+ ConfigFile: "package",
+ Value: "notused",
+ Profiles: []byte(server.ProfileNames[0]),
+ },
+ }
+
+ remapConfigParams := []tc.Parameter{
+ tc.Parameter{
+ Name: "not_location",
+ ConfigFile: "cachekey.config",
+ Value: "notinconfig",
+ Profiles: []byte(`["global"]`),
+ },
+ }
+
+ cdn := &tc.CDN{
+ DomainName: "cdndomain.example",
+ Name: "my-cdn-name",
+ }
+
+ topologies := []tc.Topology{}
+ cgs := []tc.CacheGroupNullable{}
+ serverCapabilities := map[int]map[ServerCapability]struct{}{}
+ dsRequiredCapabilities := map[int]map[ServerCapability]struct{}{}
+ configDir := `/opt/trafficserver/etc/trafficserver`
+
+ cfg, err := MakeRemapDotConfig(server, dses, dss, dsRegexes,
serverParams, cdn, remapConfigParams, topologies, cgs, serverCapabilities,
dsRequiredCapabilities, configDir, &RemapDotConfigOpts{HdrComment: hdr})
+ if err != nil {
+ t.Fatal(err)
+ }
+ txt := cfg.Text
+
+ txt = strings.TrimSpace(txt)
+
+ testComment(t, txt, hdr)
+
+ txtLines := strings.Split(txt, "\n")
+
+ if len(txtLines) != 4 { // 2 remaps plus header comment plus blank
+ t.Fatalf("expected a comment header, a blank line, and 2 remaps
from HTTP_AND_HTTPS DS, actual: '%v' count %v", txt, len(txtLines))
+ }
+
+ remapLine := txtLines[2]
+
+ if !strings.HasPrefix(remapLine, "map") {
+ t.Errorf("expected to start with 'map', actual '%v'", txt)
+ }
+
+ if 1 != strings.Count(remapLine, "cachekey.so") {
+ t.Errorf("expected remap on edge server to contain a single
cachekey plugin, actual '%v'", txt)
+ }
+
+ if !strings.Contains(remapLine, "@plugin=tslua.so
@pparam=uri-manipulator.lua @plugin=cachekey.so") {
+ t.Errorf("expected cachekey to come after tslua, actual '%v'",
txt)
+ }
+ if strings.Contains(remapLine, "__CACHEKEY_DIRECTIVE__") {
+ t.Errorf("expected raw remap cachekey directive to be replaced,
actual '%v'", txt)
+ }
+ if count := strings.Count(remapLine, "cachekey.so"); count != 1 { //
Individual line should only have 1 slice.so
+ t.Errorf("expected raw remap cachekey directive to be replaced
not duplicated, actual count %v '%v'", count, txt)
+ }
+ if count := strings.Count(txt, "cachekey.so"); count != 2 { // All
lines should have 2 slice.so - HTTP and HTTPS lines
+ t.Errorf("expected raw remap range directive to have one
cachekey.so for HTTP and one for HTTPS remap, actual count %v '%v'", count, txt)
+ }
+}
+
func TestMakeRemapDotConfigRawRemapWithoutRangeDirective(t *testing.T) {
hdr := "myHeaderComment"