-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add loki_ingester_rf1_segment_age_seconds metric
This commit adds a new metric loki_ingester_rf1_segment_age_seconds. It also cleans up a lot of the code that is used to report metrics for segments and adds a new SegmentsStats struct to get data from a SegmentWriter.
- Loading branch information
1 parent
4f534d7
commit f29a3f3
Showing
8 changed files
with
246 additions
and
124 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
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,132 @@ | ||
package wal | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/loki/v3/pkg/logproto" | ||
|
||
"github.com/prometheus/prometheus/model/labels" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func BenchmarkManager_Append(t *testing.B) { | ||
lbs := labels.Labels{{ | ||
Name: "foo", | ||
Value: "bar", | ||
}} | ||
|
||
for i := 0; i < t.N; i++ { | ||
t.StopTimer() | ||
m, err := NewManager(Config{ | ||
MaxSegmentSize: 8 * 1024 * 1024, // 8MB | ||
MaxSegments: 64, // 512MB | ||
}, NewMetrics(nil)) | ||
require.NoError(t, err) | ||
t.StartTimer() | ||
for { | ||
// Write as much data as possible. | ||
entries := []*logproto.Entry{{ | ||
Timestamp: time.Now(), | ||
Line: strings.Repeat("b", 1024), | ||
}} | ||
_, err = m.Append(AppendRequest{ | ||
TenantID: "1", | ||
Labels: lbs, | ||
LabelsStr: lbs.String(), | ||
Entries: entries, | ||
}) | ||
if errors.Is(err, ErrFull) { | ||
break | ||
} | ||
require.NoError(t, err) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkManager_Append_Parallel(t *testing.B) { | ||
lbs := labels.Labels{{ | ||
Name: "foo", | ||
Value: "bar", | ||
}} | ||
|
||
for i := 0; i < t.N; i++ { | ||
t.StopTimer() | ||
m, err := NewManager(Config{ | ||
MaxSegmentSize: 8 * 1024 * 1024, // 8MB | ||
MaxSegments: 64, // 512MB | ||
}, NewMetrics(nil)) | ||
require.NoError(t, err) | ||
wg := sync.WaitGroup{} | ||
t.StartTimer() | ||
for i := 0; i < 100; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for { | ||
// Write as much data as possible. | ||
entries := []*logproto.Entry{{ | ||
Timestamp: time.Now(), | ||
Line: strings.Repeat("b", 1024), | ||
}} | ||
_, appendErr := m.Append(AppendRequest{ | ||
TenantID: "1", | ||
Labels: lbs, | ||
LabelsStr: lbs.String(), | ||
Entries: entries, | ||
}) | ||
if errors.Is(appendErr, ErrFull) { | ||
break | ||
} | ||
require.NoError(t, appendErr) | ||
} | ||
}() | ||
} | ||
wg.Wait() | ||
} | ||
} | ||
|
||
func BenchmarkManager_Append_Parallel_MultipleStreams(t *testing.B) { | ||
for i := 0; i < t.N; i++ { | ||
t.StopTimer() | ||
m, err := NewManager(Config{ | ||
MaxSegmentSize: 8 * 1024 * 1024, // 8MB | ||
MaxSegments: 64, // 512MB | ||
}, NewMetrics(nil)) | ||
require.NoError(t, err) | ||
wg := sync.WaitGroup{} | ||
t.StartTimer() | ||
for i := 0; i < 100; i++ { | ||
wg.Add(1) | ||
go func(i int) { | ||
defer wg.Done() | ||
for { | ||
lbs := labels.Labels{{ | ||
Name: "foo", | ||
Value: strconv.Itoa(i), | ||
}} | ||
// Write as much data as possible. | ||
entries := []*logproto.Entry{{ | ||
Timestamp: time.Now(), | ||
Line: strings.Repeat("b", 1024), | ||
}} | ||
_, appendErr := m.Append(AppendRequest{ | ||
TenantID: "1", | ||
Labels: lbs, | ||
LabelsStr: lbs.String(), | ||
Entries: entries, | ||
}) | ||
if errors.Is(appendErr, ErrFull) { | ||
break | ||
} | ||
require.NoError(t, appendErr) | ||
} | ||
}(i) | ||
} | ||
wg.Wait() | ||
} | ||
} |
Oops, something went wrong.