cleaning up
parent
9e5da1ef45
commit
73a90ed2ae
2
go.mod
2
go.mod
|
|
@ -34,7 +34,7 @@ require (
|
|||
github.com/alexellis/go-execute v0.0.0-20200124154445-8697e4e28c5e // indirect
|
||||
github.com/alexellis/hmac v0.0.0-20180624211220-5c52ab81c0de // indirect
|
||||
github.com/atotto/clipboard v0.1.2
|
||||
github.com/derailed/tview v0.3.5
|
||||
github.com/derailed/tview v0.3.6
|
||||
github.com/drone/envsubst v1.0.2 // indirect
|
||||
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f // indirect
|
||||
github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -157,6 +157,8 @@ github.com/derailed/tview v0.3.4 h1:PnF64fLqm48LEjC/XwOS7JufDgFuuPYx85YVt5t3rwE=
|
|||
github.com/derailed/tview v0.3.4/go.mod h1:yApPszFU62FoaGkf7swy2nIdV/h7Nid3dhMSVy6+OFI=
|
||||
github.com/derailed/tview v0.3.5 h1:1vKqcJIiZtLAs5moX9c38+BbBSYhPgFq0ZndnVNVNFc=
|
||||
github.com/derailed/tview v0.3.5/go.mod h1:yApPszFU62FoaGkf7swy2nIdV/h7Nid3dhMSVy6+OFI=
|
||||
github.com/derailed/tview v0.3.6 h1:9PyX6Nu1vs9mCVfvV2q2fwT/dZta0dBGr4ZPjCF1KnU=
|
||||
github.com/derailed/tview v0.3.6/go.mod h1:GJ3k/TIzEE+sj1L09/usk6HrkjsdadSsb03eHgPbcII=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
|
||||
|
|
|
|||
|
|
@ -16,8 +16,10 @@ const (
|
|||
mxCacheExpiry = 1 * time.Minute
|
||||
)
|
||||
|
||||
// MetricsDial tracks global metric server handle.
|
||||
var MetricsDial *MetricsServer
|
||||
|
||||
// DialMetrics dials the metrics server.
|
||||
func DialMetrics(c Connection) *MetricsServer {
|
||||
if MetricsDial == nil {
|
||||
MetricsDial = NewMetricsServer(c)
|
||||
|
|
@ -26,6 +28,7 @@ func DialMetrics(c Connection) *MetricsServer {
|
|||
return MetricsDial
|
||||
}
|
||||
|
||||
// ResetMetrics resets the metric server handle.
|
||||
func ResetMetrics() {
|
||||
MetricsDial = nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ type (
|
|||
FgColor Color `yaml:"fgColor"`
|
||||
}
|
||||
|
||||
// ColorBorder tracks border styles.
|
||||
// Border tracks border styles.
|
||||
Border struct {
|
||||
FgColor Color `yaml:"fgColor"`
|
||||
FocusColor Color `yaml:"focusColor"`
|
||||
|
|
@ -179,7 +179,7 @@ func (c Color) String() string {
|
|||
return string(c)
|
||||
}
|
||||
|
||||
// AsColor returns a view color.
|
||||
// Color returns a view color.
|
||||
func (c Color) Color() tcell.Color {
|
||||
if c == DefaultColor {
|
||||
return tcell.ColorDefault
|
||||
|
|
@ -190,7 +190,7 @@ func (c Color) Color() tcell.Color {
|
|||
return tcell.GetColor(c.String())
|
||||
}
|
||||
|
||||
// AsColors converts series string colors to colors.
|
||||
// Colors converts series string colors to colors.
|
||||
func (c Colors) Colors() []tcell.Color {
|
||||
cc := make([]tcell.Color, 0, len(c))
|
||||
for _, color := range c {
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// Pulse tracks pulses.
|
||||
type Pulse struct {
|
||||
NonResource
|
||||
}
|
||||
|
||||
// List lists out pulses.
|
||||
func (h *Pulse) List(ctx context.Context, ns string) ([]runtime.Object, error) {
|
||||
return nil, fmt.Errorf("NYI")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ const (
|
|||
FlashErr
|
||||
)
|
||||
|
||||
// LevelMessage tracks an message and severity.
|
||||
type LevelMessage struct {
|
||||
Level FlashLevel
|
||||
Text string
|
||||
|
|
@ -29,6 +30,7 @@ func newClearMessage() LevelMessage {
|
|||
return LevelMessage{}
|
||||
}
|
||||
|
||||
// IsClear returns true if message is empty.
|
||||
func (l LevelMessage) IsClear() bool {
|
||||
return l.Text == ""
|
||||
}
|
||||
|
|
@ -56,6 +58,7 @@ type Flash struct {
|
|||
msgChan chan LevelMessage
|
||||
}
|
||||
|
||||
// NewFlash returns a new instance.
|
||||
func NewFlash(dur time.Duration) *Flash {
|
||||
return &Flash{
|
||||
delay: dur,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type Pulse struct {
|
|||
data health.Checks
|
||||
}
|
||||
|
||||
// NewPulse returns a new pulse.
|
||||
func NewPulse(gvr string) *Pulse {
|
||||
return &Pulse{
|
||||
gvr: gvr,
|
||||
|
|
@ -42,6 +43,7 @@ func NewPulse(gvr string) *Pulse {
|
|||
}
|
||||
}
|
||||
|
||||
// Watch monitors pulses.
|
||||
func (p *Pulse) Watch(ctx context.Context) {
|
||||
p.Refresh(ctx)
|
||||
go p.updater(ctx)
|
||||
|
|
|
|||
|
|
@ -14,16 +14,19 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// PulseHealth tracks resources health.
|
||||
type PulseHealth struct {
|
||||
factory dao.Factory
|
||||
}
|
||||
|
||||
// NewPulseHealth returns a new instance.
|
||||
func NewPulseHealth(f dao.Factory) *PulseHealth {
|
||||
return &PulseHealth{
|
||||
factory: f,
|
||||
}
|
||||
}
|
||||
|
||||
// List returns a canned collection of resources health.
|
||||
func (h *PulseHealth) List(ctx context.Context, ns string) ([]runtime.Object, error) {
|
||||
defer func(t time.Time) {
|
||||
log.Debug().Msgf("PulseHealthCheck %v", time.Since(t))
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ func (OpenFaas) Header(ns string) HeaderRow {
|
|||
}
|
||||
|
||||
// Render renders a chart to screen.
|
||||
func (f OpenFaas) Render(o interface{}, ns string, r *Row) error {
|
||||
fn, ok := o.(OpenFaasRes)
|
||||
func (o OpenFaas) Render(i interface{}, ns string, r *Row) error {
|
||||
fn, ok := i.(OpenFaasRes)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected OpenFaasRes, but got %T", o)
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ func (f OpenFaas) Render(o interface{}, ns string, r *Row) error {
|
|||
}
|
||||
|
||||
r.ID = client.FQN(fn.Function.Namespace, fn.Function.Name)
|
||||
r.Fields = make(Fields, 0, len(f.Header(ns)))
|
||||
r.Fields = make(Fields, 0, len(o.Header(ns)))
|
||||
if client.IsAllNamespaces(ns) {
|
||||
r.Fields = append(r.Fields, fn.Function.Namespace)
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ func (f OpenFaas) Render(o interface{}, ns string, r *Row) error {
|
|||
strconv.Itoa(int(fn.Function.InvocationCount)),
|
||||
strconv.Itoa(int(fn.Function.Replicas)),
|
||||
strconv.Itoa(int(fn.Function.AvailableReplicas)),
|
||||
asStatus(f.diagnose(status)),
|
||||
asStatus(o.diagnose(status)),
|
||||
toAge(metav1.Time{Time: time.Now()}),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func (ReplicaSet) Header(ns string) HeaderRow {
|
|||
}
|
||||
|
||||
// Render renders a K8s resource to screen.
|
||||
func (s ReplicaSet) Render(o interface{}, ns string, r *Row) error {
|
||||
func (r ReplicaSet) Render(o interface{}, ns string, row *Row) error {
|
||||
raw, ok := o.(*unstructured.Unstructured)
|
||||
if !ok {
|
||||
return fmt.Errorf("Expected ReplicaSet, but got %T", o)
|
||||
|
|
@ -61,18 +61,18 @@ func (s ReplicaSet) Render(o interface{}, ns string, r *Row) error {
|
|||
return err
|
||||
}
|
||||
|
||||
r.ID = client.MetaFQN(rs.ObjectMeta)
|
||||
r.Fields = make(Fields, 0, len(s.Header(ns)))
|
||||
row.ID = client.MetaFQN(rs.ObjectMeta)
|
||||
row.Fields = make(Fields, 0, len(r.Header(ns)))
|
||||
if client.IsAllNamespaces(ns) {
|
||||
r.Fields = append(r.Fields, rs.Namespace)
|
||||
row.Fields = append(row.Fields, rs.Namespace)
|
||||
}
|
||||
r.Fields = append(r.Fields,
|
||||
row.Fields = append(row.Fields,
|
||||
rs.Name,
|
||||
strconv.Itoa(int(*rs.Spec.Replicas)),
|
||||
strconv.Itoa(int(rs.Status.Replicas)),
|
||||
strconv.Itoa(int(rs.Status.ReadyReplicas)),
|
||||
mapToStr(rs.Labels),
|
||||
asStatus(s.diagnose(rs)),
|
||||
asStatus(r.diagnose(rs)),
|
||||
toAge(rs.ObjectMeta.CreationTimestamp),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,23 +4,26 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
// var dots = []rune{' ', '⠂', '⠶', '⠿'}
|
||||
var dots = []rune{' ', '⠂', '▤', '▥'}
|
||||
|
||||
// var dots = []rune{' ', '⠂', '▤', '▇'}
|
||||
|
||||
// Segment represents a dial segment.
|
||||
type Segment []int
|
||||
|
||||
// Segments represents a collection of segments.
|
||||
type Segments []Segment
|
||||
|
||||
// Matrics represents a number dial.
|
||||
type Matrix [][]rune
|
||||
|
||||
// Orientation tracks char orientations.
|
||||
type Orientation int
|
||||
|
||||
// DotMatrix tracks a char matrix.
|
||||
type DotMatrix struct {
|
||||
row, col int
|
||||
}
|
||||
|
||||
// NewDotMatrix returns a new matrix.
|
||||
func NewDotMatrix(row, col int) DotMatrix {
|
||||
return DotMatrix{
|
||||
row: row,
|
||||
|
|
@ -28,6 +31,7 @@ func NewDotMatrix(row, col int) DotMatrix {
|
|||
}
|
||||
}
|
||||
|
||||
// Print prints the matrix.
|
||||
func (d DotMatrix) Print(n int) Matrix {
|
||||
m := make(Matrix, d.row)
|
||||
segs := asSegments(n)
|
||||
|
|
@ -67,6 +71,7 @@ func asSegments(n int) Segment {
|
|||
}
|
||||
}
|
||||
|
||||
// CharFor return a char based on row/col.
|
||||
func (s Segment) CharFor(row, col int) rune {
|
||||
c := ' '
|
||||
segs := ToSegments(row, col)
|
||||
|
|
@ -101,6 +106,7 @@ var segs = map[int][][]int{
|
|||
4: [][]int{[]int{4, 6}, []int{6}, []int{5, 6}},
|
||||
}
|
||||
|
||||
// ToSegments return path segments.
|
||||
func ToSegments(row, col int) []int {
|
||||
return segs[row][col]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,13 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// DeltaSame represents no difference.
|
||||
DeltaSame delta = iota
|
||||
|
||||
// DeltaMore represents a higher value.
|
||||
DeltaMore
|
||||
|
||||
// DeltaLess represents a lower value.
|
||||
DeltaLess
|
||||
|
||||
gaugeFmt = "0%dd"
|
||||
|
|
@ -38,6 +43,7 @@ func (g *Gauge) IsDial() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// Add adds a new metric.
|
||||
func (g *Gauge) Add(m Metric) {
|
||||
g.mx.Lock()
|
||||
defer g.mx.Unlock()
|
||||
|
|
@ -73,6 +79,7 @@ func (g *Gauge) drawNum(sc tcell.Screen, ok bool, o image.Point, n int, dn delta
|
|||
}
|
||||
}
|
||||
|
||||
// Draw draws the primitive.
|
||||
func (g *Gauge) Draw(sc tcell.Screen) {
|
||||
g.Component.Draw(sc)
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ func (f *Flash) StylesChanged(s *config.Styles) {
|
|||
f.SetTextColor(s.FgColor())
|
||||
}
|
||||
|
||||
// Watch watches for flash changes.
|
||||
func (f *Flash) Watch(ctx context.Context, c model.FlashChan) {
|
||||
defer log.Debug().Msgf("Flash Canceled!")
|
||||
for {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ func NewAlias(gvr client.GVR) ResourceViewer {
|
|||
return &a
|
||||
}
|
||||
|
||||
// Init initialiazes the view.
|
||||
func (a *Alias) Init(ctx context.Context) error {
|
||||
if err := a.ResourceViewer.Init(ctx); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// // ExitStatus indicates UI exit conditions.
|
||||
// ExitStatus indicates UI exit conditions.
|
||||
var ExitStatus = ""
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ func (p *Pulse) PulseChanged(c *health.Check) {
|
|||
v.Add(tchart.Metric{OK: c.Tally(health.OK), Fault: c.Tally(health.Toast)})
|
||||
}
|
||||
|
||||
// PulseLoadFailed notifies the load failed.
|
||||
// PulseFailed notifies the load failed.
|
||||
func (p *Pulse) PulseFailed(err error) {
|
||||
p.app.Flash().Err(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue