Skip to content

Commit

Permalink
changing response_latency buckets some more, making exponential and c…
Browse files Browse the repository at this point in the history
…onfigurable
  • Loading branch information
slim-bean committed May 15, 2019
1 parent cc60398 commit 5aac00f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cmd/loki-canary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func main() {
interval := flag.Duration("interval", 1000*time.Millisecond, "Duration between log entries")
size := flag.Int("size", 100, "Size in bytes of each log line")
wait := flag.Duration("wait", 60*time.Second, "Duration to wait for log entries before reporting them lost")
buckets := flag.Int("buckets", 10, "Number of buckets in the response_latency histogram")
flag.Parse()

if *addr == "" {
Expand All @@ -51,7 +52,7 @@ func main() {

_, _ = fmt.Fprintf(os.Stderr, "Connecting to loki at %v, querying for label '%v' with value '%v'\n", u.String(), *lName, *lVal)

c := comparator.NewComparator(os.Stderr, *wait, 1*time.Second)
c := comparator.NewComparator(os.Stderr, *wait, 1*time.Second, *buckets)
w := writer.NewWriter(os.Stdout, c, *interval, *size)
r := reader.NewReader(os.Stderr, c, u, *user, *pass)

Expand Down
16 changes: 9 additions & 7 deletions pkg/comparator/comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ var (
Name: "unexpected_entries",
Help: "counts a log entry received which was not expected (e.g. duplicate, received after reported missing)",
})
responseLatency = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: "loki_canary",
Name: "response_latency",
Help: "is how long it takes for log lines to be returned from Loki in seconds.",
Buckets: []float64{1, 5, 10, 30, 60, 90, 120, 300},
})
responseLatency prometheus.Histogram
)

type Comparator struct {
Expand All @@ -54,7 +49,7 @@ type Comparator struct {
done chan struct{}
}

func NewComparator(writer io.Writer, maxWait time.Duration, pruneInterval time.Duration) *Comparator {
func NewComparator(writer io.Writer, maxWait time.Duration, pruneInterval time.Duration, buckets int) *Comparator {
c := &Comparator{
w: writer,
entries: []*time.Time{},
Expand All @@ -64,6 +59,13 @@ func NewComparator(writer io.Writer, maxWait time.Duration, pruneInterval time.D
done: make(chan struct{}),
}

responseLatency = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: "loki_canary",
Name: "response_latency",
Help: "is how long it takes for log lines to be returned from Loki in seconds.",
Buckets: prometheus.ExponentialBuckets(0.5, 2, buckets),
})

go c.run()

return c
Expand Down
21 changes: 18 additions & 3 deletions pkg/comparator/comparator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestComparatorEntryReceivedOutOfOrder(t *testing.T) {
unexpectedEntries = &mockCounter{}

actual := &bytes.Buffer{}
c := NewComparator(actual, 1*time.Hour, 1*time.Hour)
c := NewComparator(actual, 1*time.Hour, 1*time.Hour, 1)

t1 := time.Now()
t2 := t1.Add(1 * time.Second)
Expand All @@ -44,6 +44,11 @@ func TestComparatorEntryReceivedOutOfOrder(t *testing.T) {
assert.Equal(t, 1, outOfOrderEntries.(*mockCounter).count)
assert.Equal(t, 0, unexpectedEntries.(*mockCounter).count)
assert.Equal(t, 0, missingEntries.(*mockCounter).count)

// This avoids a panic on subsequent test execution,
// seems ugly but was easy, and multiple instantiations
// of the comparator should be an error
prometheus.Unregister(responseLatency)
}

func TestComparatorEntryReceivedNotExpected(t *testing.T) {
Expand All @@ -52,7 +57,7 @@ func TestComparatorEntryReceivedNotExpected(t *testing.T) {
unexpectedEntries = &mockCounter{}

actual := &bytes.Buffer{}
c := NewComparator(actual, 1*time.Hour, 1*time.Hour)
c := NewComparator(actual, 1*time.Hour, 1*time.Hour, 1)

t1 := time.Now()
t2 := t1.Add(1 * time.Second)
Expand All @@ -78,6 +83,11 @@ func TestComparatorEntryReceivedNotExpected(t *testing.T) {
assert.Equal(t, 0, outOfOrderEntries.(*mockCounter).count)
assert.Equal(t, 1, unexpectedEntries.(*mockCounter).count)
assert.Equal(t, 0, missingEntries.(*mockCounter).count)

// This avoids a panic on subsequent test execution,
// seems ugly but was easy, and multiple instantiations
// of the comparator should be an error
prometheus.Unregister(responseLatency)
}

func TestEntryNeverReceived(t *testing.T) {
Expand All @@ -86,7 +96,7 @@ func TestEntryNeverReceived(t *testing.T) {
unexpectedEntries = &mockCounter{}

actual := &bytes.Buffer{}
c := NewComparator(actual, 5*time.Millisecond, 2*time.Millisecond)
c := NewComparator(actual, 5*time.Millisecond, 2*time.Millisecond, 1)

t1 := time.Now()
t2 := t1.Add(1 * time.Millisecond)
Expand Down Expand Up @@ -117,6 +127,11 @@ func TestEntryNeverReceived(t *testing.T) {
assert.Equal(t, 0, unexpectedEntries.(*mockCounter).count)
assert.Equal(t, 1, missingEntries.(*mockCounter).count)

// This avoids a panic on subsequent test execution,
// seems ugly but was easy, and multiple instantiations
// of the comparator should be an error
prometheus.Unregister(responseLatency)

}

type mockCounter struct {
Expand Down

0 comments on commit 5aac00f

Please sign in to comment.