-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[coordinator] Add Carbon ingest latency metrics (#3045)
- Loading branch information
1 parent
d6c526d
commit de4894f
Showing
5 changed files
with
190 additions
and
65 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,90 @@ | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package ingest | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/uber-go/tally" | ||
) | ||
|
||
// LatencyBuckets are a set of latency buckets useful for measuring things. | ||
type LatencyBuckets struct { | ||
WriteLatencyBuckets tally.DurationBuckets | ||
IngestLatencyBuckets tally.DurationBuckets | ||
} | ||
|
||
// NewLatencyBuckets returns write and ingest latency buckets useful for | ||
// measuring ingest latency (i.e. time from datapoint/sample created to time | ||
// ingested) and write latency (i.e. time from received a sample from remote | ||
// source to completion of that write locally). | ||
func NewLatencyBuckets() (LatencyBuckets, error) { | ||
upTo1sBuckets, err := tally.LinearDurationBuckets(0, 100*time.Millisecond, 10) | ||
if err != nil { | ||
return LatencyBuckets{}, err | ||
} | ||
|
||
upTo10sBuckets, err := tally.LinearDurationBuckets(time.Second, 500*time.Millisecond, 18) | ||
if err != nil { | ||
return LatencyBuckets{}, err | ||
} | ||
|
||
upTo60sBuckets, err := tally.LinearDurationBuckets(10*time.Second, 5*time.Second, 11) | ||
if err != nil { | ||
return LatencyBuckets{}, err | ||
} | ||
|
||
upTo60mBuckets, err := tally.LinearDurationBuckets(0, 5*time.Minute, 12) | ||
if err != nil { | ||
return LatencyBuckets{}, err | ||
} | ||
upTo60mBuckets = upTo60mBuckets[1:] // Remove the first 0s to get 5 min aligned buckets | ||
|
||
upTo6hBuckets, err := tally.LinearDurationBuckets(time.Hour, 30*time.Minute, 12) | ||
if err != nil { | ||
return LatencyBuckets{}, err | ||
} | ||
|
||
upTo24hBuckets, err := tally.LinearDurationBuckets(6*time.Hour, time.Hour, 19) | ||
if err != nil { | ||
return LatencyBuckets{}, err | ||
} | ||
upTo24hBuckets = upTo24hBuckets[1:] // Remove the first 6h to get 1 hour aligned buckets | ||
|
||
var writeLatencyBuckets tally.DurationBuckets | ||
writeLatencyBuckets = append(writeLatencyBuckets, upTo1sBuckets...) | ||
writeLatencyBuckets = append(writeLatencyBuckets, upTo10sBuckets...) | ||
writeLatencyBuckets = append(writeLatencyBuckets, upTo60sBuckets...) | ||
writeLatencyBuckets = append(writeLatencyBuckets, upTo60mBuckets...) | ||
|
||
var ingestLatencyBuckets tally.DurationBuckets | ||
ingestLatencyBuckets = append(ingestLatencyBuckets, upTo1sBuckets...) | ||
ingestLatencyBuckets = append(ingestLatencyBuckets, upTo10sBuckets...) | ||
ingestLatencyBuckets = append(ingestLatencyBuckets, upTo60sBuckets...) | ||
ingestLatencyBuckets = append(ingestLatencyBuckets, upTo60mBuckets...) | ||
ingestLatencyBuckets = append(ingestLatencyBuckets, upTo6hBuckets...) | ||
ingestLatencyBuckets = append(ingestLatencyBuckets, upTo24hBuckets...) | ||
|
||
return LatencyBuckets{ | ||
WriteLatencyBuckets: writeLatencyBuckets, | ||
IngestLatencyBuckets: ingestLatencyBuckets, | ||
}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package ingest | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLatencyBuckets(t *testing.T) { | ||
buckets, err := NewLatencyBuckets() | ||
require.NoError(t, err) | ||
|
||
// NB(r): Bucket length is tested just to sanity check how many buckets we are creating | ||
require.Equal(t, 50, len(buckets.WriteLatencyBuckets.AsDurations())) | ||
|
||
// NB(r): Bucket values are tested to sanity check they look right | ||
// nolint: lll | ||
expected := "[0s 100ms 200ms 300ms 400ms 500ms 600ms 700ms 800ms 900ms 1s 1.5s 2s 2.5s 3s 3.5s 4s 4.5s 5s 5.5s 6s 6.5s 7s 7.5s 8s 8.5s 9s 9.5s 10s 15s 20s 25s 30s 35s 40s 45s 50s 55s 1m0s 5m0s 10m0s 15m0s 20m0s 25m0s 30m0s 35m0s 40m0s 45m0s 50m0s 55m0s]" | ||
actual := fmt.Sprintf("%v", buckets.WriteLatencyBuckets.AsDurations()) | ||
require.Equal(t, expected, actual) | ||
|
||
// NB(r): Bucket length is tested just to sanity check how many buckets we are creating | ||
require.Equal(t, 80, len(buckets.IngestLatencyBuckets.AsDurations())) | ||
|
||
// NB(r): Bucket values are tested to sanity check they look right | ||
// nolint: lll | ||
expected = "[0s 100ms 200ms 300ms 400ms 500ms 600ms 700ms 800ms 900ms 1s 1.5s 2s 2.5s 3s 3.5s 4s 4.5s 5s 5.5s 6s 6.5s 7s 7.5s 8s 8.5s 9s 9.5s 10s 15s 20s 25s 30s 35s 40s 45s 50s 55s 1m0s 5m0s 10m0s 15m0s 20m0s 25m0s 30m0s 35m0s 40m0s 45m0s 50m0s 55m0s 1h0m0s 1h30m0s 2h0m0s 2h30m0s 3h0m0s 3h30m0s 4h0m0s 4h30m0s 5h0m0s 5h30m0s 6h0m0s 6h30m0s 7h0m0s 8h0m0s 9h0m0s 10h0m0s 11h0m0s 12h0m0s 13h0m0s 14h0m0s 15h0m0s 16h0m0s 17h0m0s 18h0m0s 19h0m0s 20h0m0s 21h0m0s 22h0m0s 23h0m0s 24h0m0s]" | ||
actual = fmt.Sprintf("%v", buckets.IngestLatencyBuckets.AsDurations()) | ||
require.Equal(t, expected, actual) | ||
} |
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