You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/08/19 15:28:27 UTC

[GitHub] [trafficcontrol] shamrickus commented on a change in pull request #6120: TP tests alert logging

shamrickus commented on a change in pull request #6120:
URL: https://github.com/apache/trafficcontrol/pull/6120#discussion_r692204233



##########
File path: .github/actions/tp-integration-tests/entrypoint.sh
##########
@@ -167,56 +182,42 @@ to_build() {
 
   export $(<"${ciab_dir}/variables.env" sed '/^#/d') # defines TV_ADMIN_USER/PASSWORD
   envsubst <"${resources}/riak.json" >riak.conf
-  truncate --size=0 warning.log error.log event.log info.log
+  truncate -s0 out.log
 
-  ./traffic_ops_golang --cfg ./cdn.conf --dbcfg ./database.conf -riakcfg riak.conf &
-  tail -f warning.log 2>&1 | color_and_prefix "${yellow_bg}" 'Traffic Ops WARN' &
-  tail -f error.log 2>&1 | color_and_prefix "${red_bg}" 'Traffic Ops ERR' &
-  tail -f event.log 2>&1 | color_and_prefix "${gray_bg}" 'Traffic Ops EVT' &
+  ./traffic_ops_golang --cfg ./cdn.conf --dbcfg ./database.conf -riakcfg riak.conf >out.log 2>&1 &
+  popd
 }
 
 tp_build() {
-  cd "${REPO_DIR}/traffic_portal"
+  pushd "${REPO_DIR}/traffic_portal"
   npm ci
   bower install
   grunt dist
 
   cp "${resources}/config.js" ./conf/
   touch tp.log access.log out.log err.log
-  sudo forever --minUptime 5000 --spinSleepTime 2000 -f -o out.log start server.js &
-  tail -f err.log 2>&1 | color_and_prefix "${red_bg}" "Node Err" &
+  sudo forever --minUptime 5000 --spinSleepTime 2000 -f -o out.log start server.js >out.log 2>&1 &

Review comment:
       `-o out.log` is redundant.

##########
File path: .github/actions/tp-integration-tests/cdn.json
##########
@@ -13,11 +13,11 @@
 	"traffic_ops_golang": {
 		"insecure": true,
 		"port": "6443",
-		"log_location_error": "error.log",
-		"log_location_warning": "warning.log",
-		"log_location_info": "info.log",
-		"log_location_debug": null,
-		"log_location_event": "event.log",
+		"log_location_error": "stderr",
+		"log_location_warning": "stderr",
+		"log_location_info": "stdout",
+		"log_location_debug": "stderr",

Review comment:
       Shouldn't this be `stdout`?

##########
File path: traffic_portal/test/integration/config.model.ts
##########
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { hasProperty } from "./CommonUtils/utils";
+
+/** Possible levels of TO Alerts */
+export type AlertLevel = "success" | "info" | "warning" | "error";
+
+/**
+ * Checks whether an object is a valid Alert level.
+ *
+ * @param s The object to check.
+ * @returns Whether or not `s` is an AlertLevel.
+ */
+export function isAlertLevel(s: unknown): s is AlertLevel {
+    if (typeof(s) !== "string") {
+        return false;
+    }
+    switch (s) {
+        case "success":
+        case "info":
+        case "warning":
+        case "error":
+            return true;
+    }
+    return false;
+}
+
+/** TO API Alerts */
+export interface Alert {
+    level: AlertLevel;
+    text: string;
+}
+
+/**
+ * Checks whether an object is an Alert like the ones TO normally returns.
+ *
+ * @param a The object to check.
+ * @returns Whether or not `a` is an Alert.
+ */
+export function isAlert(a: unknown): a is Alert {
+    if (typeof(a) !== "object" || a === null) {
+        return false;
+    }
+    if (!hasProperty(a, "level") || !hasProperty(a, "text", "string")) {
+        return false;
+    }
+    return isAlertLevel(a.level);
+}
+
+/**
+ * Logs an alert to the appropriate console stream based on its `level`.
+ *
+ * @param a The Alert to log.
+ * @param prefix Optional prefix for the log message
+ */
+export function logAlert(a: Alert, prefix?: string): void {
+    let logfunc;
+    let pre = (prefix ?? "").trimStart();
+    switch (a.level) {
+        case "success":
+            logfunc = console.log;
+            pre = `SUCCESS: ${pre}`;
+            break;
+        case "info":
+            logfunc = console.info
+            pre = `INFO: ${pre}`;
+            break;
+        case "warning":
+            logfunc = console.warn
+            pre = `WARN: ${pre}`;
+            break;
+        case "error":
+            logfunc = console.error
+            pre = `ERROR: ${pre}`;
+            break;
+    }
+    logfunc(pre, a.text);
+}
+
+/** TestingConfig is the type of a testing configuration. */
+export interface TestingConfig {
+	/** This is login information for a user with admin-level permissions. */
+	readonly login: {
+		readonly password: string;
+		readonly username: string;
+	};
+	/** The URL at which the Traffic Ops API can be accessed. */
+	readonly apiUrl: string;
+	/** The URL at which Traffic Portal is served - root path. */
+	readonly baseUrl: string;
+	/** Logging alert levels that are enabled. */
+	readonly alertLevels?: Array<AlertLevel>;
+}
+
+/**
+ * Checks if a passed object is a valid testing configuration.
+ *
+ * @param c The object to check.
+ * @returns `true`, always. When the check fails, it throws an error that
+ * explains why.
+ */
+export function isTestingConfig(c: unknown): c is TestingConfig {
+	if (typeof(c) !== "object") {
+		throw new Error(`testing configuration must be an object, not a '${typeof(c)}'`);
+	}
+	if (c === null) {

Review comment:
       nit: null check before `typeof` is marginally faster in case of nulls
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org