Skip to content

Commit

Permalink
Merge pull request #58 from reactiveops/rs/dashboard-cleanup
Browse files Browse the repository at this point in the history
Dashboard cleanup
  • Loading branch information
robscott authored Apr 17, 2019
2 parents c1d1566 + 0a4050d commit cc9ca63
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 419 deletions.
37 changes: 21 additions & 16 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2019 ReactiveOps
//
// Licensed 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.

package dashboard

import (
Expand Down Expand Up @@ -44,22 +58,13 @@ func MainHandler(w http.ResponseWriter, r *http.Request, c conf.Configuration, k
JSON: template.JS(jsonData),
}
tmpl, err := template.New(TemplateName).Funcs(template.FuncMap{
"getWarningWidth": func(rs validator.ResultSummary, fullWidth int) uint {
return uint(float64(rs.Successes+rs.Warnings) / float64(rs.Successes+rs.Warnings+rs.Errors) * float64(fullWidth))
},
"getSuccessWidth": func(rs validator.ResultSummary, fullWidth int) uint {
return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Errors) * float64(fullWidth))
},
"getIcon": func(rm validator.ResultMessage) string {
switch rm.Type {
case "success":
return "fas fa-check"
case "warning":
return "fas fa-exclamation"
default:
return "fas fa-times"
}
},
"getWarningWidth": getWarningWidth,
"getSuccessWidth": getSuccessWidth,
"getWeatherIcon": getWeatherIcon,
"getWeatherText": getWeatherText,
"getGrade": getGrade,
"getScore": getScore,
"getIcon": getIcon,
}).ParseFiles(TemplateFile)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
104 changes: 104 additions & 0 deletions pkg/dashboard/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2019 ReactiveOps
//
// Licensed 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.

package dashboard

import (
"github.com/reactiveops/fairwinds/pkg/validator"
)

func getWarningWidth(rs validator.ResultSummary, fullWidth int) uint {
return uint(float64(rs.Successes+rs.Warnings) / float64(rs.Successes+rs.Warnings+rs.Errors) * float64(fullWidth))
}

func getSuccessWidth(rs validator.ResultSummary, fullWidth int) uint {
return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Errors) * float64(fullWidth))
}

func getGrade(rs validator.ResultSummary) string {
score := getScore(rs)
if score >= 97 {
return "A+"
} else if score >= 93 {
return "A"
} else if score >= 90 {
return "A-"
} else if score >= 87 {
return "B+"
} else if score >= 83 {
return "B"
} else if score >= 80 {
return "B-"
} else if score >= 77 {
return "C+"
} else if score >= 73 {
return "C"
} else if score >= 70 {
return "C-"
} else if score >= 67 {
return "D+"
} else if score >= 63 {
return "D"
} else if score >= 60 {
return "D-"
} else {
return "F"
}
}

func getScore(rs validator.ResultSummary) uint {
total := (rs.Successes * 2) + rs.Warnings + (rs.Errors * 2)
return uint((float64(rs.Successes*2) / float64(total)) * 100)
}

func getWeatherIcon(rs validator.ResultSummary) string {
score := getScore(rs)
if score >= 90 {
return "fa-sun"
} else if score >= 80 {
return "fa-cloud-sun"
} else if score >= 70 {
return "fa-cloud"
} else if score >= 60 {
return "fa-cloud-rain"
} else {
return "fa-cloud-showers-heavy"
}
}

func getWeatherText(rs validator.ResultSummary) string {
score := getScore(rs)
if score >= 90 {
return "Smooth sailing"
} else if score >= 80 {
return "Mostly smooth sailing"
} else if score >= 70 {
return "Smooth sailing within sight"
} else if score >= 60 {
return "A little stormy"
} else {
return "Storms ahead, be careful"
}
}

func getIcon(rm validator.ResultMessage) string {
switch rm.Type {
case "success":
return "fas fa-check"
case "warning":
return "fas fa-exclamation"
default:
return "fas fa-times"
}
}
36 changes: 21 additions & 15 deletions pkg/dashboard/templates/dashboard.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Muli:300,400,700" rel="stylesheet">
<link rel="stylesheet" href="/static/css/normalize.css">
<link rel="stylesheet" href="/static/css/main.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
Expand All @@ -27,25 +27,31 @@
<div class="header-content">
<img class="logo" src="/static/images/logo.png" alt="Fairwinds" />
<div class="header-right">
<a href="https://reactiveops.com?source=fairwinds">
<span class="by-text">by</span>
<a href="https://reactiveops.com?source=fairwinds" target="_blank">
<span class="oss-text">Open Source Project By</span>
<img class="ro-logo" src="/static/images/ro-logo.png" alt="ReactiveOps" />
</a>
</div>
</div>
</div>

<div class="dashboard-content">
<div class="charts">
<div class="cluster-score chart-section">
<h3>Overall Score:</h3>
<div style="width:510px; height: 400px; left: -100px; position: relative;">
<canvas id="clusterScoreChart"></canvas>
<div class="namespace">
<h3>Cluster Overview</h3>
<div class="cluster-overview">
<div class="cluster-score">
<div class="weather"><i class="fas {{ getWeatherIcon .AuditData.ClusterSummary }}"></i></div>
<div class="sailing">{{ getWeatherText .AuditData.ClusterSummary }}</div>
<div class="scores">Grade: <strong>{{ getGrade .AuditData.ClusterSummary }}</strong> | Score: <strong>{{ getScore .AuditData.ClusterSummary }}%</strong></div>
</div>
</div>
<div class="namespace-score chart-section">
<h3>Scores By Namespace:</h3>
<canvas id="namespaceScoreChart"></canvas>
<div class="result-messages">
<ul>
<li class="success"><i class="fas fa-check"></i> {{ .AuditData.ClusterSummary.Successes }} checks passed</li>
<li class="warning"><i class="fas fa-exclamation"></i> {{ .AuditData.ClusterSummary.Warnings }} checks had warnings</li>
<li class="error"><i class="fas fa-times"></i> {{ .AuditData.ClusterSummary.Errors }} checks had errors</li>
</ul>
</div>
<canvas id="clusterScoreChart"></canvas>
</div>
</div>

Expand All @@ -59,7 +65,7 @@
<div class="name"><span class="caret-expander"></span>{{ .Type }}: <strong>{{ .Name }}</strong></div>

{{ range .PodResults}}
<div class="extra">
<div class="result-messages">
<h4>Pod Spec:</h4>
<ul>
{{ range $message := .Messages}}
Expand All @@ -68,7 +74,7 @@
</ul>
</div>
{{ range .ContainerResults}}
<div class="extra">
<div class="result-messages">
<h4>Container: {{ .Name }}</h4>
<ul>
{{ range $message := .Messages}}
Expand Down Expand Up @@ -96,7 +102,7 @@
</div>

<div class="footer">
&copy; 2019, <a href="https://reactiveops.com?source=fairwinds">ReactiveOps Inc.</a>
<a href="https://reactiveops.com?source=fairwinds" target="_blank">&copy;2019 ReactiveOps Inc.</a>
</div>

<script src="/static/js/charts.js">
Expand Down
Loading

0 comments on commit cc9ca63

Please sign in to comment.