Skip to content

Commit

Permalink
Add duration time to stale EDS
Browse files Browse the repository at this point in the history
  • Loading branch information
MorrisLaw committed Feb 6, 2019
1 parent 7aee01b commit 2329291
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
15 changes: 14 additions & 1 deletion istioctl/pkg/writer/pilot/status.go
Expand Up @@ -21,6 +21,7 @@ import (
"sort"
"strings"
"text/tabwriter"
"time"

"istio.io/istio/pilot/pkg/proxy/envoy/v2"
)
Expand Down Expand Up @@ -103,5 +104,17 @@ func xdsStatus(sent, acked string) string {
if sent == acked {
return "SYNCED"
}
return "STALE"
timeSent, _ := parseTime(sent)
timeAcked, _ := parseTime(acked)
if timeAcked.Equal(time.Time{}) {
return "STALE (Never Acknowledged)"
}
timeDiff := timeSent.Sub(timeAcked)
return fmt.Sprintf("STALE (%v)", timeDiff.String())
}

func parseTime(s string) (time.Time, error) {
s = strings.Split(s, " m=+")[0]
layout := "2006-01-02 15:04:05 +0000 MST"
return time.Parse(layout, s)
}
18 changes: 18 additions & 0 deletions istioctl/pkg/writer/pilot/status_test.go
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"io/ioutil"
"testing"
"time"

"github.com/stretchr/testify/assert"

Expand All @@ -38,6 +39,7 @@ func TestStatusWriter_PrintAll(t *testing.T) {
input: map[string][]v2.SyncStatus{
"pilot1": statusInput1(),
"pilot2": statusInput2(),
"pilot3": statusInput3(),
},
want: "testdata/multiStatusMultiPilot.txt",
},
Expand Down Expand Up @@ -177,3 +179,19 @@ func statusInput2() []v2.SyncStatus {
},
}
}

func statusInput3() []v2.SyncStatus {
return []v2.SyncStatus{
{
ProxyID: "proxy3",
ProxyVersion: "1.0",
ClusterSent: "2009-11-10 23:00:00 +0000 UTC m=+0.000000001",
ClusterAcked: time.Time{}.String(),
ListenerAcked: "2009-11-10 23:00:00 +0000 UTC m=+0.000000001",
EndpointSent: "2009-11-10 23:00:00 +0000 UTC m=+0.000000001",
EndpointAcked: time.Time{}.String(),
RouteSent: "2009-11-10 23:00:00 +0000 UTC m=+0.000000001",
RouteAcked: "2009-11-10 23:00:00 +0000 UTC m=+0.000000001",
},
}
}
7 changes: 4 additions & 3 deletions istioctl/pkg/writer/pilot/testdata/multiStatusMultiPilot.txt
@@ -1,3 +1,4 @@
PROXY CDS LDS EDS RDS PILOT VERSION
proxy1 STALE SYNCED SYNCED (100%) NOT SENT pilot1 1.0
proxy2 STALE SYNCED STALE (0%) SYNCED pilot2 1.0
NAME CDS LDS EDS RDS PILOT VERSION
proxy1 STALE (1h0m0s) SYNCED SYNCED (100%) NOT SENT pilot1 1.0
proxy2 STALE (1h0m0s) SYNCED STALE (1h0m0s) (0%) SYNCED pilot2 1.0
proxy3 STALE (Never Acknowledged) NOT SENT STALE (Never Acknowledged) (0%) SYNCED pilot3 1.0
7 changes: 4 additions & 3 deletions istioctl/pkg/writer/pilot/testdata/multiStatusSinglePilot.txt
@@ -1,3 +1,4 @@
PROXY CDS LDS EDS RDS PILOT VERSION
proxy1 STALE SYNCED SYNCED (100%) NOT SENT pilot1 1.0
proxy2 STALE SYNCED STALE (0%) SYNCED pilot1 1.0
NAME CDS LDS EDS RDS PILOT VERSION
proxy1 STALE (1h0m0s) SYNCED SYNCED (100%) NOT SENT pilot1 1.0
proxy2 STALE (1h0m0s) SYNCED STALE (1h0m0s) (0%) SYNCED pilot1 1.0

4 changes: 2 additions & 2 deletions istioctl/pkg/writer/pilot/testdata/singleStatus.txt
@@ -1,2 +1,2 @@
PROXY CDS LDS EDS RDS PILOT VERSION
proxy2 STALE SYNCED STALE (0%) SYNCED pilot2 1.0
NAME CDS LDS EDS RDS PILOT VERSION
proxy2 STALE (1h0m0s) SYNCED STALE (1h0m0s) (0%) SYNCED pilot2 1.0

0 comments on commit 2329291

Please sign in to comment.