You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2020/04/22 18:37:01 UTC

[trafficcontrol] branch master updated: Fixed logging.yaml generation. (#4653)

This is an automated email from the ASF dual-hosted git repository.

rawlin 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 3531f96  Fixed logging.yaml generation. (#4653)
3531f96 is described below

commit 3531f9649cec0e49859825fc452d348830c95d65
Author: alficles <al...@gmail.com>
AuthorDate: Wed Apr 22 12:36:48 2020 -0600

    Fixed logging.yaml generation. (#4653)
    
    The logging.yaml file was generating a separate logs section for each
    log file. This was allowing the yaml parser in ATS to accept the file,
    but fail to process any but one of the log files. This corrects that by
    putting all the logs in the same object.
---
 CHANGELOG.md                         |  1 +
 lib/go-atscfg/loggingdotyaml.go      |  6 ++-
 lib/go-atscfg/loggingdotyaml_test.go | 99 ++++++++++++++++++++++++++++++++++++
 lib/go-atscfg/meta.go                |  1 +
 4 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d113b26..ee6ae21 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -55,6 +55,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Traffic Ops, Traffic Monitor, Traffic Stats, and Grove are now compiled using Go version 1.14. This requires a Traffic Vault config update (see note below).
 - Existing installations **must** enable TLSv1.1 for Traffic Vault in order for Traffic Ops to reach it. See [Enabling TLS 1.1](https://traffic-control-cdn.readthedocs.io/en/latest/admin/traffic_vault.html#tv-admin-enable-tlsv1-1) in the Traffic Vault administrator's guide for instructions.
 - Changed the `totalBytes` property of responses to GET requests to `/deliveryservice_stats` to the more appropriate `totalKiloBytes` in API 2.x
+- Fix to traffic_ops_ort to generate logging.yaml files correctly.
 
 ### Deprecated/Removed
 - The Traffic Ops `db/admin.pl` script has now been removed. Please use the `db/admin` binary instead.
diff --git a/lib/go-atscfg/loggingdotyaml.go b/lib/go-atscfg/loggingdotyaml.go
index 02e3968..84851de 100644
--- a/lib/go-atscfg/loggingdotyaml.go
+++ b/lib/go-atscfg/loggingdotyaml.go
@@ -81,6 +81,7 @@ func MakeLoggingDotYAML(
 		}
 	}
 
+	var firstObject = true
 	for i := 0; i < maxLogObjects; i++ {
 		logObjectField := "LogObject"
 		if i > 0 {
@@ -99,7 +100,10 @@ func MakeLoggingDotYAML(
 			logObjectRollingSizeMb := paramData[logObjectField+".RollingSizeMb"]
 			logObjectFilters := paramData[logObjectField+".Filters"]
 
-			text += "\nlogs:\n"
+			if firstObject {
+				text += "\nlogs:\n"
+				firstObject = false
+			}
 			text += "- mode: " + logObjectType + "\n"
 			text += "  filename: " + logObjectFilename + "\n"
 			text += "  format: " + logObjectFormat + "\n"
diff --git a/lib/go-atscfg/loggingdotyaml_test.go b/lib/go-atscfg/loggingdotyaml_test.go
index 9d2707a..121afc0 100644
--- a/lib/go-atscfg/loggingdotyaml_test.go
+++ b/lib/go-atscfg/loggingdotyaml_test.go
@@ -20,8 +20,11 @@ package atscfg
  */
 
 import (
+	"fmt"
 	"strings"
 	"testing"
+
+	yaml "gopkg.in/yaml.v2"
 )
 
 func TestMakeLoggingDotYAML(t *testing.T) {
@@ -57,3 +60,99 @@ func TestMakeLoggingDotYAML(t *testing.T) {
 		t.Errorf("expected config to omit unknown config 'ShouldNotBeHere', actual: '%v'", txt)
 	}
 }
+
+func TestMakeLoggingDotYAMLMultiFormat(t *testing.T) {
+	profileName := "myProfile"
+	toolName := "myToolName"
+	toURL := "https://myto.example.net"
+	paramData := map[string]string{
+		"LogFormat.Name":           "myFormatName0",
+		"LogFormat.Format":         "myFormat0",
+		"LogFormat1.Name":          "myFormatName1",
+		"LogFormat1.Format":        "myFormat1",
+		"LogFormat9.Name":          "myFormatName9",
+		"LogFormat9.Format":        "myFormat9",
+		"LogFormat2.Name":          "myFormatName2",
+		"LogFormat2.Format":        "myFormat2",
+		"LogFormat11.Name":         "shouldNotBeHere11",
+		"LogFormat11.Format":       "shouldNotBeHere11",
+		"LogObject.Filename":       "myFilename0",
+		"LogObject.Format":         "myFormatName0",
+		"LogObject.RollingEnabled": "myRollingEnabled",
+		"LogFormat.Invalid":        "ShouldNotBeHere",
+		"LogObject.Invalid":        "ShouldNotBeHere",
+		"LogObject2.Filename":      "myFilename2",
+		"LogObject2.Format":        "myFormatName2",
+		"LogObject11.Filename":     "shouldNotBeHere11",
+		"LogObject11.Format":       "shouldNotBeHere11",
+		"LogObject9.Filename":      "myFilename9",
+		"LogObject9.Format":        "myFormatName9",
+		"LogObject1.Filename":      "myFilename1",
+		"LogObject1.Format":        "myFormatName1",
+	}
+
+	txt := MakeLoggingDotYAML(profileName, paramData, toolName, toURL)
+
+	testComment(t, txt, profileName, toolName, toURL)
+
+	if !strings.Contains(txt, "myFormatName") {
+		t.Errorf("expected config to contain LogFormat.Name 'myFormatName', actual: '%v'", txt)
+	}
+	if !strings.Contains(txt, "myFormat") {
+		t.Errorf("expected config to contain LogFormat.Format 'myFormat', actual: '%v'", txt)
+	}
+	if !strings.Contains(txt, "myFilename") {
+		t.Errorf("expected config to contain LogFormat.Filename 'myFilename', actual: '%v'", txt)
+	}
+	if !strings.Contains(txt, "myRollingEnabled") {
+		t.Errorf("expected config to contain LogFormat.RollingEnabled 'myRollingEnabled', actual: '%v'", txt)
+	}
+	if strings.Contains(txt, "ShouldNotBeHere") {
+		t.Errorf("expected config to omit unknown config 'ShouldNotBeHere', actual: '%v'", txt)
+	}
+
+	var v struct {
+		Formats []struct {
+			Name   string
+			Format string
+		}
+		Logs []struct {
+			Mode                 string
+			Filename             string
+			Format               string
+			Rolling_enabled      string
+			Rolling_interval_sec int
+			Rolling_offset_hr    int
+			Rolling_size_mb      int
+		}
+	}
+	err := yaml.Unmarshal([]byte(txt), &v)
+	if err != nil {
+		t.Errorf("expected config to parse as yaml document '%v', actual: '%v'", err, txt)
+	}
+	if len(v.Formats) != 4 {
+		t.Errorf("expected config to contain 4 'format' elements: '%v', actual: '%v'", v, txt)
+		return
+	}
+	if len(v.Logs) != 4 {
+		t.Errorf("expected config to contain 4 'logs' elements: '%v', actual: '%v'", v, txt)
+		return
+	}
+	for i, n := range []int{0, 1, 2, 9} {
+		if v.Formats[i].Name != fmt.Sprintf("myFormatName%d", n) {
+			t.Errorf("expected config to contain formats.name 'myFormatName%d' in position %d, actual: '%v', full: '%v'", n, i, v.Formats[i].Name, txt)
+		}
+		if v.Formats[i].Format != fmt.Sprintf("myFormat%d", n) {
+			t.Errorf("expected config to contain formats.format 'myFormat%d' in position %d, actual: '%v', full: '%v'", n, i, v.Formats[i].Format, txt)
+		}
+		if v.Logs[i].Format != fmt.Sprintf("myFormatName%d", n) {
+			t.Errorf("expected config to contain logs.format 'myFormatName%d' in position %d, actual: '%v', full: '%v'", n, i, v.Logs[i].Format, txt)
+		}
+		if v.Logs[i].Filename != fmt.Sprintf("myFilename%d", n) {
+			t.Errorf("expected config to contain logs.filename 'myFilename%d' in position %d, actual: '%v', full: '%v'", n, i, v.Logs[i].Filename, txt)
+		}
+		if v.Logs[i].Mode != "ascii" {
+			t.Errorf("expected config to contain logs.mode 'ascii' in position %d, actual: '%v', full: '%v'", i, v.Logs[i].Mode, txt)
+		}
+	}
+}
diff --git a/lib/go-atscfg/meta.go b/lib/go-atscfg/meta.go
index 9c67445..d2583ce 100644
--- a/lib/go-atscfg/meta.go
+++ b/lib/go-atscfg/meta.go
@@ -188,6 +188,7 @@ func getScope(cfgFile string, scopeParams map[string]string) tc.ATSConfigMetaDat
 		cfgFile == "drop_qstring.config",
 		cfgFile == "logs_xml.config",
 		cfgFile == "logging.config",
+		cfgFile == "logging.yaml",
 		cfgFile == "plugin.config",
 		cfgFile == "records.config",
 		cfgFile == "storage.config",