Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duration proxy status #11568

Merged
merged 1 commit into from Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion istioctl/pkg/writer/pilot/status.go
Expand Up @@ -21,6 +21,7 @@ import (
"sort"
"strings"
"text/tabwriter"
"time"

v2 "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 @@
NAME 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
6 changes: 3 additions & 3 deletions istioctl/pkg/writer/pilot/testdata/multiStatusSinglePilot.txt
@@ -1,3 +1,3 @@
NAME 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 @@
NAME 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