You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ro...@apache.org on 2022/05/31 15:47:42 UTC

[trafficcontrol] branch master updated: t3c/regex_revalidate: remove STALE keyword for default rule. (#6865)

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 7a91a324bc t3c/regex_revalidate: remove STALE keyword for default rule. (#6865)
7a91a324bc is described below

commit 7a91a324bc83f16b74eaae5d80780a3c05eee240
Author: Brian Olsen <br...@comcast.com>
AuthorDate: Tue May 31 09:47:36 2022 -0600

    t3c/regex_revalidate: remove STALE keyword for default rule. (#6865)
    
    * t3c/regex_revalidate: remove STALE keyword for default rule.
    
    * change type RevalType convention and use
    
    * add STALE check to regression test
---
 CHANGELOG.md                                    |  1 +
 cache-config/testing/ort-tests/t3c-jobs_test.go |  4 ++--
 lib/go-atscfg/regexrevalidatedotconfig.go       | 21 ++++++++++++---------
 lib/go-atscfg/regexrevalidatedotconfig_test.go  |  2 +-
 4 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 532c07e57c..67bdef8de6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Added layered profile feature to 4.0 for `GET` /servers/, `POST` /servers/, `PUT` /servers/{id} and `DELETE` /servers/{id}.
 - Added a Traffic Ops endpoint and Traffic Portal page to view all CDNi configuration update requests and approve or deny.
 - Added layered profile feature to 4.0 for `GET` /deliveryservices/{id}/servers/ and /deliveryservices/{id}/servers/eligible.
+- Change to t3c regex_revalidate so that STALE is no longer explicitly added for default revalidate rule for ATS version backwards compatibility.
 
 ### Fixed
 - [#6291](https://github.com/apache/trafficcontrol/issues/6291) Prevent Traffic Ops from modifying and/or deleting reserved statuses.
diff --git a/cache-config/testing/ort-tests/t3c-jobs_test.go b/cache-config/testing/ort-tests/t3c-jobs_test.go
index 980ee67ce3..f0f1c2546f 100644
--- a/cache-config/testing/ort-tests/t3c-jobs_test.go
+++ b/cache-config/testing/ort-tests/t3c-jobs_test.go
@@ -74,8 +74,8 @@ func TestT3CJobs(t *testing.T) {
 			}
 			if strings.Contains(line, "refresh-test") {
 				sawRefresh = true
-				if !strings.HasSuffix(line, "STALE") {
-					t.Errorf("expected regex_revalidate.config refresh-test line to contain 'STALE', actual: %s", line)
+				if strings.HasSuffix(line, "STALE") || strings.HasSuffix(line, "MISS") {
+					t.Errorf("expected regex_revalidate.config refresh-test line to contain no type, actual: %s", line)
 				}
 			}
 			if strings.Contains(line, "refetch-test") {
diff --git a/lib/go-atscfg/regexrevalidatedotconfig.go b/lib/go-atscfg/regexrevalidatedotconfig.go
index 86674ad289..6cc11baedb 100644
--- a/lib/go-atscfg/regexrevalidatedotconfig.go
+++ b/lib/go-atscfg/regexrevalidatedotconfig.go
@@ -41,6 +41,12 @@ const DefaultMaxRevalDurationDays = 90
 const JobKeywordPurge = "PURGE"
 const RegexRevalidateMinTTL = time.Hour
 
+type RevalType string
+
+const RevalTypeMiss = RevalType("MISS")
+const RevalTypeStale = RevalType("STALE")
+const RevalTypeDefault = RevalTypeStale
+
 const ContentTypeRegexRevalidateDotConfig = ContentTypeTextASCII
 const LineCommentRegexRevalidateDotConfig = LineCommentHash
 
@@ -110,8 +116,8 @@ func MakeRegexRevalidateDotConfig(
 	txt := makeHdrComment(opt.HdrComment)
 	for _, job := range cfgJobs {
 		txt += job.AssetURL + " " + strconv.FormatInt(job.PurgeEnd.Unix(), 10)
-		if job.Type != "" {
-			txt += " " + job.Type
+		if job.Type != "" && job.Type != RevalTypeDefault {
+			txt += " " + string(job.Type)
 		}
 		txt += "\n"
 	}
@@ -127,7 +133,7 @@ func MakeRegexRevalidateDotConfig(
 type revalJob struct {
 	AssetURL string
 	PurgeEnd time.Time
-	Type     string // MISS or STALE (default)
+	Type     RevalType // RevalTypeMiss or RevalTypeStale (default)
 }
 
 type jobsSort []revalJob
@@ -188,21 +194,18 @@ func filterJobs(tcJobs []InvalidationJob, maxReval time.Duration, minTTL time.Du
 	return newJobs
 }
 
-const MISS = "MISS"
-const STALE = "STALE"
-
 // processRefetch determines the type of Invalidation, returns the corresponding jobtype
 // and "cleans" the regex URL for the asset to be invalidated. REFETCH trumps REFRESH,
 // whether in the AssetURL or as InvalidationType
-func processRefetch(invalidationType, assetURL string) (string, string) {
+func processRefetch(invalidationType, assetURL string) (RevalType, string) {
 
 	if (len(invalidationType) > 0 && invalidationType == tc.REFETCH) || strings.HasSuffix(assetURL, RefetchSuffix) {
 		assetURL = strings.TrimSuffix(assetURL, RefetchSuffix)
-		return MISS, assetURL
+		return RevalTypeMiss, assetURL
 	}
 
 	// Default value. Either the InvalidationType == REFRESH
 	// or the suffix is ##REFRESH## or neither
 	assetURL = strings.TrimSuffix(assetURL, RefreshSuffix)
-	return STALE, assetURL
+	return RevalTypeStale, assetURL
 }
diff --git a/lib/go-atscfg/regexrevalidatedotconfig_test.go b/lib/go-atscfg/regexrevalidatedotconfig_test.go
index 1073a93468..a2aea7023e 100644
--- a/lib/go-atscfg/regexrevalidatedotconfig_test.go
+++ b/lib/go-atscfg/regexrevalidatedotconfig_test.go
@@ -122,7 +122,7 @@ func TestMakeRegexRevalidateDotConfig(t *testing.T) {
 	if strings.Contains(txt, "##REFETCH##") || !strings.Contains(txt, "MISS") {
 		t.Errorf("##REFETCH## directive not properly handled '%v'", txt)
 	}
-	if strings.Contains(txt, "##REFRESH##") || !strings.Contains(txt, "STALE") {
+	if strings.Contains(txt, "##REFRESH##") {
 		t.Errorf("##REFRESH## directive not properly handled '%v'", txt)
 	}
 }