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

rawlin pushed a commit to branch 4.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/4.1.x by this push:
     new 4b6caf2  [BACKPORT #4543] 'fixed' grafana scripted dashboard to use 
exact hostname instead of regular expression match (#4729)
4b6caf2 is described below

commit 4b6caf295e69c24de1c13da4db3de5338b66f4e2
Author: Rawlin Peters <[email protected]>
AuthorDate: Thu May 28 10:27:57 2020 -0600

    [BACKPORT #4543] 'fixed' grafana scripted dashboard to use exact hostname 
instead of regular expression match (#4729)
    
    * 'fixed' grafana scripted dashboard to use exact hostname instead of 
regular expression match (#4543)
    
    * 'fixed' grafana scripted dashboard to use exact hostname instead of regex 
match
    
    * Re-added brackets and weird formatting
    
    (cherry picked from commit 13e570f54ac48215229bb0fe97da768a19814480)
    
    * Add CHANGELOG entry
    
    Co-authored-by: ocket8888 <[email protected]>
---
 CHANGELOG.md                                |  1 +
 traffic_stats/grafana/traffic_ops_server.js | 88 +++++++++++++----------------
 2 files changed, 41 insertions(+), 48 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 12a73bf..7d6acf7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -62,6 +62,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - Removed audit logging from the `POST /api/x/serverchecks` Traffic Ops API 
endpoint in order to reduce audit log spam
 - Fixed the `GET /api/x/jobs` and `GET /api/x/jobs/:id` Traffic Ops API routes 
to allow falling back to Perl via the routing blacklist
 - Fixed audit logging from the `/jobs` APIs to bring them back to the same 
level of information provided by TO-Perl
+- Fixed #4541: traffic_ops_server.js searches based on which= and can find 
data for multiple servers
 
 ### Deprecated/Removed
 - The Traffic Ops `db/admin.pl` script has now been removed. Please use the 
`db/admin` binary instead.
diff --git a/traffic_stats/grafana/traffic_ops_server.js 
b/traffic_stats/grafana/traffic_ops_server.js
index 9efcfbd..786bb7b 100644
--- a/traffic_stats/grafana/traffic_ops_server.js
+++ b/traffic_stats/grafana/traffic_ops_server.js
@@ -13,53 +13,45 @@
      limitations under the License.
 */
 
-/* global _ */
-
 /*
  * Scripted dashboard for traffic ops.
  *
  * Based on the grafana scripted.js script (which is ASF 2.0 licensed).
  */
 
-
-
-// accessible variables in this scope
-var window, document, ARGS, $, jQuery, moment, kbn;
+'use strict';
 
 // Setup some variables
 var dashboard;
 
-// All url parameters are available via the ARGS object
+// All URL parameters are available via the ARGS object
 var ARGS;
 
-// Intialize a skeleton with nothing but a rows array and service object
+// Intialize a skeleton with nothing but a rows array and service object,
+// and setting default time and refresh interval.
 dashboard = {
-  rows : [],
+  refresh: "30s",
+  rows: [],
+  // time can be overridden in the URL using from/to parameters, but this is
+  // handled automatically in grafana core during dashboard initialization
+  time: {
+    from: "now-24h",
+    to: "now"
+  }
 };
 
+let which = 'argName';
 
-// Set default time
-// time can be overriden in the url using from/to parameters, but this is
-// handled automatically in grafana core during dashboard initialization
-dashboard.time = {
-  from: "now-24h",
-  to: "now"
-};
-
-var which = 'argName';
-
-if(!_.isUndefined(ARGS.which)) {
+if (ARGS.which !== undefined) {
   which = ARGS.which;
 }
 
 // Set a title
 dashboard.title = which;
-//set refresh interval
-dashboard.refresh = "30s";
-
 
 {
-  dashboard.rows.push(    {
+  dashboard.rows.push(
+    {
       "height": "250px",
       "panels": [
         {
@@ -108,7 +100,7 @@ dashboard.refresh = "30s";
             {
               "measurement": "bandwidth.1min",
               "tags": {},
-              "query": "SELECT mean(value) FROM \"monthly\".\"bandwidth.1min\" 
WHERE hostname= '" + which + "' and $timeFilter GROUP BY time(60s)",
+              "query": `SELECT mean(value) FROM "monthly"."bandwidth.1min" 
WHERE hostname= '${which}' and $timeFilter GROUP BY time(60s)`,
               "rawQuery": true,
               "refId": "A",
               "policy": "default",
@@ -222,7 +214,7 @@ dashboard.refresh = "30s";
             {
               "measurement": "connections.1min",
               "tags": {},
-              "query": "SELECT mean(value) FROM 
\"monthly\".\"connections.1min\" WHERE hostname= '" + which + "' and 
$timeFilter GROUP BY time(60s)",
+              "query": `SELECT mean(value) FROM "monthly"."connections.1min" 
WHERE hostname= '${which}' and $timeFilter GROUP BY time(60s)`,
               "rawQuery": true,
               "refId": "A",
               "policy": "default",
@@ -308,9 +300,9 @@ dashboard.refresh = "30s";
               "resultFormat": "time_series",
               "tags": [
                 {
-                  "key": "host",
-                  "operator": "=~",
-                  "value": "/" + which + "/"
+                  key: "host",
+                  operator: "=",
+                  value: which
                 }
               ],
               "groupBy": [
@@ -499,9 +491,9 @@ dashboard.refresh = "30s";
               "resultFormat": "time_series",
               "tags": [
                 {
-                  "key": "host",
-                  "operator": "=~",
-                  "value": "/" + which + "/"
+                  key: "host",
+                  operator: "=",
+                  value: which
                 }
               ],
               "groupBy": [
@@ -626,9 +618,9 @@ dashboard.refresh = "30s";
               "resultFormat": "time_series",
               "tags": [
                 {
-                  "key": "host",
-                  "operator": "=~",
-                  "value": "/" + which + "/"
+                  key: "host",
+                  operator: "=",
+                  value: which
                 }
               ],
               "groupBy": [
@@ -781,9 +773,9 @@ dashboard.refresh = "30s";
               "resultFormat": "time_series",
               "tags": [
                 {
-                  "key": "host",
-                  "operator": "=~",
-                  "value": "/" + which + "/"
+                  key: "host",
+                  operator: "=",
+                  value: which
                 }
               ],
               "groupBy": [
@@ -836,9 +828,9 @@ dashboard.refresh = "30s";
               "resultFormat": "time_series",
               "tags": [
                 {
-                  "key": "host",
-                  "operator": "=~",
-                  "value": "/" + which + "/"
+                  key: "host",
+                  operator: "=",
+                  value: which
                 }
               ],
               "groupBy": [
@@ -968,10 +960,10 @@ dashboard.refresh = "30s";
               "dsType": "influxdb",
               "resultFormat": "time_series",
               "tags": [
-              {
-                  "key": "hostname",
-                  "operator": "=~",
-                  "value": "/" + which + "/"
+                {
+                  key: "hostname",
+                  operator: "=",
+                  value: which
                 }
               ],
               "groupBy": [
@@ -1106,9 +1098,9 @@ dashboard.refresh = "30s";
               "resultFormat": "time_series",
               "tags": [
                 {
-                  "key": "host",
-                  "operator": "=~",
-                  "value": "/" + which + "/"
+                  key: "host",
+                  operator: "=",
+                  value: which
                 }
               ],
               "groupBy": [

Reply via email to