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 688d01a  Add logging scope to logging.yaml generation for ATS 9 
support (#5791)
688d01a is described below

commit 688d01a61369ab813d5ef77800bac51ff61222e7
Author: Evan Zelkowitz <[email protected]>
AuthorDate: Wed May 5 13:53:44 2021 -0600

    Add logging scope to logging.yaml generation for ATS 9 support (#5791)
---
 CHANGELOG.md                    |  1 +
 lib/go-atscfg/loggingdotyaml.go | 41 +++++++++++++++++++++++++----------------
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c223030..9915938 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - Add a Federation to the Ansible Dataset Loader
 - Added asynchronous status to ACME certificate generation.
 - Added headers to Traffic Portal, Traffic Ops, and Traffic Monitor to opt out 
of tracking users via Google FLoC.
+- Add logging scope for logging.yaml generation for ATS 9 support
 - `DELETE` request method for `deliveryservices/xmlId/{name}/urlkeys` and 
`deliveryservices/{id}/urlkeys`.
 - t3c: bug fix to consider plugin config files for reloading remap.config
 - t3c: Change syncds so that it only warns on package version mismatch.
diff --git a/lib/go-atscfg/loggingdotyaml.go b/lib/go-atscfg/loggingdotyaml.go
index f7a964e..34063c2 100644
--- a/lib/go-atscfg/loggingdotyaml.go
+++ b/lib/go-atscfg/loggingdotyaml.go
@@ -37,6 +37,7 @@ func MakeLoggingDotYAML(
        hdrComment string,
 ) (Cfg, error) {
        warnings := []string{}
+       requiredIndent := 0
 
        if server.Profile == nil {
                return Cfg{}, makeErr(warnings, "this server missing Profile")
@@ -47,11 +48,19 @@ func MakeLoggingDotYAML(
 
        hdr := makeHdrComment(hdrComment)
 
+       version, vWarn := getATSMajorVersion(serverParams)
+       warnings = append(warnings, vWarn...)
        // note we use the same const as logs.xml - this isn't necessarily a 
requirement, and we may want to make separate variables in the future.
        maxLogObjects := MaxLogObjects
 
        text := hdr
-       text += "\nformats: \n"
+       if version >= 9 {
+               text += "\nlogging:"
+               requiredIndent += 2
+       }
+
+       indentSpaces := strings.Repeat(" ", requiredIndent)
+       text += "\n" + indentSpaces + "formats: \n"
        for i := 0; i < maxLogObjects; i++ {
                logFormatField := "LogFormat"
                if i > 0 {
@@ -64,12 +73,12 @@ func MakeLoggingDotYAML(
                                // TODO determine if the line should be 
excluded. Perl includes it anyway, without checking.
                                warnings = append(warnings, 
fmt.Sprintf("profile '%v' has logging.yaml format '%v' Name Parameter but no 
Format Parameter. Setting blank Format!\n", *server.Profile, logFormatField))
                        }
-                       text += " - name: " + logFormatName + " \n"
-                       text += "   format: '" + format + "'\n"
+                       text += indentSpaces + " - name: " + logFormatName + " 
\n"
+                       text += indentSpaces + "   format: '" + format + "'\n"
                }
        }
 
-       text += "filters:\n"
+       text += indentSpaces + "filters:\n"
        for i := 0; i < maxLogObjects; i++ {
                logFilterField := "LogFilter"
                if i > 0 {
@@ -85,9 +94,9 @@ func MakeLoggingDotYAML(
                        if logFilterType == "" {
                                logFilterType = "accept"
                        }
-                       text += "- name: " + logFilterName + "\n"
-                       text += "  action: " + logFilterType + "\n"
-                       text += "  condition: " + filter + "\n"
+                       text += indentSpaces + " - name: " + logFilterName + 
"\n"
+                       text += indentSpaces + "   action: " + logFilterType + 
"\n"
+                       text += indentSpaces + "   condition: " + filter + "\n"
                }
        }
 
@@ -111,30 +120,30 @@ func MakeLoggingDotYAML(
                        logObjectFilters := paramData[logObjectField+".Filters"]
 
                        if firstObject {
-                               text += "\nlogs:\n"
+                               text += "\n" + indentSpaces + "logs:\n"
                                firstObject = false
                        }
-                       text += "- mode: " + logObjectType + "\n"
-                       text += "  filename: " + logObjectFilename + "\n"
-                       text += "  format: " + logObjectFormat + "\n"
+                       text += indentSpaces + " - mode: " + logObjectType + 
"\n"
+                       text += indentSpaces + "   filename: " + 
logObjectFilename + "\n"
+                       text += indentSpaces + "   format: " + logObjectFormat 
+ "\n"
 
                        if logObjectType != "pipe" {
                                if logObjectRollingEnabled != "" {
-                                       text += "  rolling_enabled: " + 
logObjectRollingEnabled + "\n"
+                                       text += indentSpaces + "   
rolling_enabled: " + logObjectRollingEnabled + "\n"
                                }
                                if logObjectRollingIntervalSec != "" {
-                                       text += "  rolling_interval_sec: " + 
logObjectRollingIntervalSec + "\n"
+                                       text += indentSpaces + "   
rolling_interval_sec: " + logObjectRollingIntervalSec + "\n"
                                }
                                if logObjectRollingOffsetHr != "" {
-                                       text += "  rolling_offset_hr: " + 
logObjectRollingOffsetHr + "\n"
+                                       text += indentSpaces + "   
rolling_offset_hr: " + logObjectRollingOffsetHr + "\n"
                                }
                                if logObjectRollingSizeMb != "" {
-                                       text += "  rolling_size_mb: " + 
logObjectRollingSizeMb + "\n"
+                                       text += indentSpaces + "   
rolling_size_mb: " + logObjectRollingSizeMb + "\n"
                                }
                        }
                        if logObjectFilters != "" {
                                logObjectFilters = 
strings.Replace(logObjectFilters, "\v", "", -1)
-                               text += "  filters: [" + logObjectFilters + 
"]\n"
+                               text += indentSpaces + "   filters: [" + 
logObjectFilters + "]\n"
                        }
                }
        }

Reply via email to