Commit f779013b authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Fixed small formatting errors of log output

- removed trailing ","s
- removed unecessary space before seconds
parent 0767a637
...@@ -74,6 +74,12 @@ func (s CountryStats) Display() string { ...@@ -74,6 +74,12 @@ func (s CountryStats) Display() string {
for cc, count := range s.counts { for cc, count := range s.counts {
output += fmt.Sprintf("%s=%d,", cc, count) output += fmt.Sprintf("%s=%d,", cc, count)
} }
// cut off trailing ","
if len(output) > 0 {
return output[:len(output)-1]
}
return output return output
} }
...@@ -163,7 +169,7 @@ func (m *Metrics) logMetrics() { ...@@ -163,7 +169,7 @@ func (m *Metrics) logMetrics() {
} }
func (m *Metrics) printMetrics() { func (m *Metrics) printMetrics() {
m.logger.Println("snowflake-stats-end", time.Now().UTC().Format("2006-01-02 15:04:05"), "(", int(metricsResolution.Seconds()), "s)") m.logger.Println("snowflake-stats-end", time.Now().UTC().Format("2006-01-02 15:04:05"), fmt.Sprintf("(%d s)", int(metricsResolution.Seconds())))
m.logger.Println("snowflake-ips", m.countryStats.Display()) m.logger.Println("snowflake-ips", m.countryStats.Display())
m.logger.Println("snowflake-idle-count", binCount(m.proxyIdleCount)) m.logger.Println("snowflake-idle-count", binCount(m.proxyIdleCount))
m.logger.Println("client-denied-count", binCount(m.clientDeniedCount)) m.logger.Println("client-denied-count", binCount(m.clientDeniedCount))
......
...@@ -419,7 +419,7 @@ func TestMetrics(t *testing.T) { ...@@ -419,7 +419,7 @@ func TestMetrics(t *testing.T) {
<-done <-done
ctx.metrics.printMetrics() ctx.metrics.printMetrics()
So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" ( 86400 s)\nsnowflake-ips CA=1,\nsnowflake-idle-count 8\nclient-denied-count 0\nclient-snowflake-match-count 0\n") So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips CA=1\nsnowflake-idle-count 8\nclient-denied-count 0\nclient-snowflake-match-count 0\n")
}) })
//Test addition of client failures //Test addition of client failures
...@@ -432,13 +432,13 @@ func TestMetrics(t *testing.T) { ...@@ -432,13 +432,13 @@ func TestMetrics(t *testing.T) {
clientOffers(ctx, w, r) clientOffers(ctx, w, r)
ctx.metrics.printMetrics() ctx.metrics.printMetrics()
So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" ( 86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 8\nclient-snowflake-match-count 0\n") So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 8\nclient-snowflake-match-count 0\n")
// Test reset // Test reset
buf.Reset() buf.Reset()
ctx.metrics.zeroMetrics() ctx.metrics.zeroMetrics()
ctx.metrics.printMetrics() ctx.metrics.printMetrics()
So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" ( 86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 0\nclient-snowflake-match-count 0\n") So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 0\nclient-snowflake-match-count 0\n")
}) })
//Test addition of client matches //Test addition of client matches
Convey("for client-proxy match", func() { Convey("for client-proxy match", func() {
...@@ -459,7 +459,7 @@ func TestMetrics(t *testing.T) { ...@@ -459,7 +459,7 @@ func TestMetrics(t *testing.T) {
<-done <-done
ctx.metrics.printMetrics() ctx.metrics.printMetrics()
So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" ( 86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 0\nclient-snowflake-match-count 8\n") So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 0\nclient-snowflake-match-count 8\n")
}) })
//Test rounding boundary //Test rounding boundary
Convey("binning boundary", func() { Convey("binning boundary", func() {
...@@ -478,12 +478,12 @@ func TestMetrics(t *testing.T) { ...@@ -478,12 +478,12 @@ func TestMetrics(t *testing.T) {
clientOffers(ctx, w, r) clientOffers(ctx, w, r)
ctx.metrics.printMetrics() ctx.metrics.printMetrics()
So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" ( 86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 8\nclient-snowflake-match-count 0\n") So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 8\nclient-snowflake-match-count 0\n")
clientOffers(ctx, w, r) clientOffers(ctx, w, r)
buf.Reset() buf.Reset()
ctx.metrics.printMetrics() ctx.metrics.printMetrics()
So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" ( 86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 16\nclient-snowflake-match-count 0\n") So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips \nsnowflake-idle-count 0\nclient-denied-count 16\nclient-snowflake-match-count 0\n")
}) })
//Test unique ip //Test unique ip
...@@ -515,7 +515,7 @@ func TestMetrics(t *testing.T) { ...@@ -515,7 +515,7 @@ func TestMetrics(t *testing.T) {
<-done <-done
ctx.metrics.printMetrics() ctx.metrics.printMetrics()
So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" ( 86400 s)\nsnowflake-ips CA=1,\nsnowflake-idle-count 8\nclient-denied-count 0\nclient-snowflake-match-count 0\n") So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips CA=1\nsnowflake-idle-count 8\nclient-denied-count 0\nclient-snowflake-match-count 0\n")
}) })
}) })
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment