cleaning up
parent
ca317cbdef
commit
dc49596f9c
|
|
@ -28,7 +28,9 @@ const (
|
||||||
cacheMXKey = "metrics"
|
cacheMXKey = "metrics"
|
||||||
cacheMXAPIKey = "metricsAPI"
|
cacheMXAPIKey = "metricsAPI"
|
||||||
checkConnTimeout = 10 * time.Second
|
checkConnTimeout = 10 * time.Second
|
||||||
CallTimeout = 5 * time.Second
|
|
||||||
|
// CallTimeout represents default api call timeout.
|
||||||
|
CallTimeout = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
var supportedMetricsAPIVersions = []string{"v1beta1"}
|
var supportedMetricsAPIVersions = []string{"v1beta1"}
|
||||||
|
|
|
||||||
|
|
@ -101,11 +101,12 @@ func (p *Popeye) List(ctx context.Context, _ string) ([]runtime.Object, error) {
|
||||||
return oo, nil
|
return oo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get fetch a resource.
|
// Get retrieves a resource.
|
||||||
func (a *Popeye) Get(_ context.Context, _ string) (runtime.Object, error) {
|
func (p *Popeye) Get(_ context.Context, _ string) (runtime.Object, error) {
|
||||||
return nil, errors.New("NYI!!")
|
return nil, errors.New("NYI!!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
// Helpers...
|
// Helpers...
|
||||||
|
|
||||||
type popFactory struct {
|
type popFactory struct {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ func (f *FishBuff) SetSuggestionFn(fn SuggestionFunc) {
|
||||||
f.suggestionFn = fn
|
f.suggestionFn = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Activate activates the command.
|
||||||
func (f *FishBuff) Activate() {
|
func (f *FishBuff) Activate() {
|
||||||
if f.suggestionFn == nil {
|
if f.suggestionFn == nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ func NewHistory(limit int) *History {
|
||||||
return &History{limit: limit}
|
return &History{limit: limit}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List returns the current command history.
|
||||||
func (h *History) List() []string {
|
func (h *History) List() []string {
|
||||||
return h.commands
|
return h.commands
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,8 @@ func (Popeye) Render(o interface{}, ns string, r *Row) error {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Helpers...
|
// Helpers...
|
||||||
|
|
||||||
// BOZO!! export!
|
|
||||||
type (
|
type (
|
||||||
// Builder represents sanitizer
|
// Builder represents a popeye report.
|
||||||
Builder struct {
|
Builder struct {
|
||||||
Report Report `json:"popeye" yaml:"popeye"`
|
Report Report `json:"popeye" yaml:"popeye"`
|
||||||
}
|
}
|
||||||
|
|
@ -96,9 +95,13 @@ type (
|
||||||
Outcome Outcome `json:"issues,omitempty" yaml:"issues,omitempty"`
|
Outcome Outcome `json:"issues,omitempty" yaml:"issues,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Outcomes represents a classification of report outcomes
|
||||||
Outcome map[string]Issues
|
Outcome map[string]Issues
|
||||||
Issues []Issue
|
|
||||||
|
|
||||||
|
// Issues represents a collection of issues.
|
||||||
|
Issues []Issue
|
||||||
|
|
||||||
|
// Issue represents a sanitization issue.
|
||||||
Issue struct {
|
Issue struct {
|
||||||
Group string `yaml:"group" json:"group"`
|
Group string `yaml:"group" json:"group"`
|
||||||
GVR string `yaml:"gvr" json:"gvr"`
|
GVR string `yaml:"gvr" json:"gvr"`
|
||||||
|
|
@ -106,16 +109,19 @@ type (
|
||||||
Message string `yaml:"message" json:"message"`
|
Message string `yaml:"message" json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tally tracks a section scores.
|
||||||
Tally struct {
|
Tally struct {
|
||||||
OK, Info, Warning, Error int
|
OK, Info, Warning, Error int
|
||||||
Count int
|
Count int
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Sum sums up tally counts.
|
||||||
func (t *Tally) Sum() int {
|
func (t *Tally) Sum() int {
|
||||||
return t.OK + t.Info + t.Warning + t.Error
|
return t.OK + t.Info + t.Warning + t.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Score returns the overall sections score in percent.
|
||||||
func (t *Tally) Score() int {
|
func (t *Tally) Score() int {
|
||||||
oks := t.OK + t.Info
|
oks := t.OK + t.Info
|
||||||
return toPerc(float64(oks), float64(oks+t.Warning+t.Error))
|
return toPerc(float64(oks), float64(oks+t.Warning+t.Error))
|
||||||
|
|
@ -128,14 +134,17 @@ func toPerc(v1, v2 float64) int {
|
||||||
return int(math.Floor((v1 / v2) * 100))
|
return int(math.Floor((v1 / v2) * 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Len returns a section length.
|
||||||
func (s Sections) Len() int {
|
func (s Sections) Len() int {
|
||||||
return len(s)
|
return len(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Swap swaps values.
|
||||||
func (s Sections) Swap(i, j int) {
|
func (s Sections) Swap(i, j int) {
|
||||||
s[i], s[j] = s[j], s[i]
|
s[i], s[j] = s[j], s[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Less compares section scores.
|
||||||
func (s Sections) Less(i, j int) bool {
|
func (s Sections) Less(i, j int) bool {
|
||||||
t1, t2 := s[i].Tally, s[j].Tally
|
t1, t2 := s[i].Tally, s[j].Tally
|
||||||
return t1.Score() < t2.Score()
|
return t1.Score() < t2.Score()
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,7 @@ func (s *Section) Render(ctx context.Context, ns string, o interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanse(s string) string {
|
func (*Section) outcomeRefs(parent *TreeNode, section render.Section) {
|
||||||
s = strings.Replace(s, "[", "(", -1)
|
|
||||||
s = strings.Replace(s, "]", ")", -1)
|
|
||||||
s = strings.Replace(s, "/", "::", -1)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Section) outcomeRefs(parent *TreeNode, section render.Section) {
|
|
||||||
for k, issues := range section.Outcome {
|
for k, issues := range section.Outcome {
|
||||||
p := NewTreeNode(section.GVR, cleanse(k))
|
p := NewTreeNode(section.GVR, cleanse(k))
|
||||||
parent.Add(p)
|
parent.Add(p)
|
||||||
|
|
@ -58,6 +51,9 @@ func (c *Section) outcomeRefs(parent *TreeNode, section render.Section) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Helpers...
|
||||||
|
|
||||||
func colorize(s string, l config.Level) string {
|
func colorize(s string, l config.Level) string {
|
||||||
c := "green"
|
c := "green"
|
||||||
switch l {
|
switch l {
|
||||||
|
|
@ -70,3 +66,10 @@ func colorize(s string, l config.Level) string {
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("[%s::]%s", c, s)
|
return fmt.Sprintf("[%s::]%s", c, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanse(s string) string {
|
||||||
|
s = strings.Replace(s, "[", "(", -1)
|
||||||
|
s = strings.Replace(s, "]", ")", -1)
|
||||||
|
s = strings.Replace(s, "/", "::", -1)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue