-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add simple sink system for latency metrics * Ignore error explicitly * Add test for stdout sink
- Loading branch information
Showing
12 changed files
with
177 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package constants | ||
|
||
const ( | ||
PingReply = "K" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package metrics | ||
|
||
import "time" | ||
|
||
// Sink is an interface for sending latency measurements. | ||
type Sink interface { | ||
SendLatencyMeasurement(fromAddr, toAddr string, measurement time.Duration) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package metrics | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
) | ||
|
||
// MultiSink sends latency measurements to multiple sinks. | ||
// Simplifies the process of sending to multiple sinks. | ||
// If no sinks are given, it will safely do nothing. | ||
type MultiSink struct { | ||
sinks []Sink | ||
} | ||
|
||
// NewMultiSink creates a new MultiSink ready to send to the given sinks. | ||
// If no sinks are given, it will safely do nothing. | ||
func NewMultiSink(sinks ...Sink) *MultiSink { | ||
return &MultiSink{ | ||
sinks: sinks, | ||
} | ||
} | ||
|
||
// SendLatencyMeasurement sends a latency measurement to all sinks. | ||
// Any errors are returned as a single joined error. | ||
func (s *MultiSink) SendLatencyMeasurement(fromAddr, toAddr string, measurement time.Duration) error { | ||
errs := make([]error, 0, len(s.sinks)) | ||
|
||
for _, sink := range s.sinks { | ||
if err := sink.SendLatencyMeasurement(fromAddr, toAddr, measurement); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
return errors.Join(errs...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package metrics | ||
|
||
import ( | ||
"log" | ||
"time" | ||
) | ||
|
||
// SinkStdout sends latency measurements to stdout. Useful for ad hoc checks. | ||
type SinkStdout struct{} | ||
|
||
// NewSinkStdout creates a new SinkStdout ready to print to stdout. | ||
func NewSinkStdout() *SinkStdout { | ||
return &SinkStdout{} | ||
} | ||
|
||
// SendLatencyMeasurement sends a latency measurement to stdout. | ||
func (s *SinkStdout) SendLatencyMeasurement(fromAddr, toAddr string, measurement time.Duration) error { | ||
log.Printf("%v -> %v latency: %v", fromAddr, toAddr, measurement) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Feature: watch latency in stdout | ||
In order to check latency in an ad hoc fashion | ||
Cyn should send the latency to stdout | ||
|
||
Scenario: no latency in stdout by default | ||
Given I run cyn -u 127.0.0.1:14567 | ||
And I run cyn -U 127.0.0.1:14567 --send-interval 200ms | ||
When I wait 1 second | ||
Then the stdout does not contain "latency" | ||
|
||
Scenario: latency is displayed in stdout when asked for | ||
Given I run cyn -u 127.0.0.1:14567 | ||
And I run cyn -U 127.0.0.1:14567 --send-interval 200ms --sinks.stdout.enabled | ||
When I wait 1 second | ||
Then the stdout contains "latency" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters