@ -845,11 +845,17 @@ func TestInstance_Volume(t *testing.T) {
err := instance . Push ( context . TODO ( ) , & logproto . PushRequest {
Streams : [ ] logproto . Stream {
{
Labels : ` { host="other"} ` ,
Labels : ` { fizz="buzz", host="other"}` ,
Entries : [ ] logproto . Entry {
{ Timestamp : time . Unix ( 0 , 1e6 ) , Line : ` msg="other" ` } ,
} ,
} ,
{
Labels : ` { foo="bar", host="other", log_stream="worker"} ` ,
Entries : [ ] logproto . Entry {
{ Timestamp : time . Unix ( 0 , 1e6 ) , Line : ` msg="other worker" ` } ,
} ,
} ,
} ,
} )
require . NoError ( t , err )
@ -864,7 +870,7 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : "{}" ,
Limit : 3 ,
Limit : 5 ,
AggregateBy : seriesvolume . Series ,
} )
require . NoError ( t , err )
@ -872,7 +878,8 @@ func TestInstance_Volume(t *testing.T) {
require . Equal ( t , [ ] logproto . Volume {
{ Name : ` { host="agent", job="3", log_stream="dispatcher"} ` , Volume : 90 } ,
{ Name : ` { host="agent", job="3", log_stream="worker"} ` , Volume : 70 } ,
{ Name : ` { host="other"} ` , Volume : 11 } ,
{ Name : ` { foo="bar", host="other", log_stream="worker"} ` , Volume : 18 } ,
{ Name : ` { fizz="buzz", host="other"} ` , Volume : 11 } ,
} , volumes . Volumes )
} )
@ -882,7 +889,7 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : ` { log_stream="dispatcher"} ` ,
Limit : 3 ,
Limit : 5 ,
AggregateBy : seriesvolume . Series ,
} )
require . NoError ( t , err )
@ -898,7 +905,7 @@ func TestInstance_Volume(t *testing.T) {
From : 5 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : "{}" ,
Limit : 3 ,
Limit : 5 ,
AggregateBy : seriesvolume . Series ,
} )
require . NoError ( t , err )
@ -932,7 +939,7 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : ` { } ` ,
Limit : 3 ,
Limit : 5 ,
TargetLabels : [ ] string { "log_stream" } ,
AggregateBy : seriesvolume . Series ,
} )
@ -940,7 +947,7 @@ func TestInstance_Volume(t *testing.T) {
require . Equal ( t , [ ] logproto . Volume {
{ Name : ` { log_stream="dispatcher"} ` , Volume : 90 } ,
{ Name : ` { log_stream="worker"} ` , Volume : 70 } ,
{ Name : ` { log_stream="worker"} ` , Volume : 88 } ,
} , volumes . Volumes )
} )
@ -950,7 +957,7 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : ` { log_stream="dispatcher"} ` ,
Limit : 3 ,
Limit : 5 ,
TargetLabels : [ ] string { "host" } ,
AggregateBy : seriesvolume . Series ,
} )
@ -967,7 +974,7 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : ` { log_stream=~".+"} ` ,
Limit : 3 ,
Limit : 5 ,
TargetLabels : [ ] string { "host" , "job" } ,
AggregateBy : seriesvolume . Series ,
} )
@ -987,32 +994,39 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : "{}" ,
Limit : 3 ,
Limit : 5 ,
AggregateBy : seriesvolume . Labels ,
} )
require . NoError ( t , err )
require . Equal ( t , [ ] logproto . Volume {
{ Name : ` host ` , Volume : 171 } ,
{ Name : ` host ` , Volume : 189 } ,
{ Name : ` log_stream ` , Volume : 178 } ,
{ Name : ` job ` , Volume : 160 } ,
{ Name : ` log_stream ` , Volume : 160 } ,
{ Name : ` foo ` , Volume : 18 } ,
{ Name : ` fizz ` , Volume : 11 } ,
} , volumes . Volumes )
} )
t . Run ( "with matchers" , func ( t * testing . T ) {
t . Run ( "with matchers it returns intersecting labels " , func ( t * testing . T ) {
instance := prepareInstance ( t )
volumes , err := instance . GetVolume ( context . Background ( ) , & logproto . VolumeRequest {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : ` { log_stream="dispatch er"} ` ,
Limit : 3 ,
Matchers : ` { log_stream="work er"} ` ,
Limit : 5 ,
AggregateBy : seriesvolume . Labels ,
} )
require . NoError ( t , err )
require . Equal ( t , [ ] logproto . Volume {
{ Name : ` log_stream ` , Volume : 90 } ,
{ Name : ` host ` , Volume : 88 } ,
{ Name : ` log_stream ` , Volume : 88 } ,
{ Name : ` job ` , Volume : 70 } ,
{ Name : ` foo ` , Volume : 18 } ,
} , volumes . Volumes )
require . NotContains ( t , volumes . Volumes , logproto . Volume { Name : ` fizz ` , Volume : 11 } )
} )
t . Run ( "excludes streams outside of time bounds" , func ( t * testing . T ) {
@ -1021,7 +1035,7 @@ func TestInstance_Volume(t *testing.T) {
From : 5 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : "{}" ,
Limit : 3 ,
Limit : 5 ,
AggregateBy : seriesvolume . Labels ,
} )
require . NoError ( t , err )
@ -1045,7 +1059,7 @@ func TestInstance_Volume(t *testing.T) {
require . NoError ( t , err )
require . Equal ( t , [ ] logproto . Volume {
{ Name : ` host ` , Volume : 171 } ,
{ Name : ` host ` , Volume : 189 } ,
} , volumes . Volumes )
} )
@ -1056,14 +1070,14 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : ` { } ` ,
Limit : 3 ,
Limit : 5 ,
TargetLabels : [ ] string { "host" } ,
AggregateBy : seriesvolume . Labels ,
} )
require . NoError ( t , err )
require . Equal ( t , [ ] logproto . Volume {
{ Name : ` host ` , Volume : 171 } ,
{ Name : ` host ` , Volume : 189 } ,
} , volumes . Volumes )
} )
@ -1073,7 +1087,7 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : ` { log_stream="dispatcher"} ` ,
Limit : 3 ,
Limit : 5 ,
TargetLabels : [ ] string { "host" } ,
AggregateBy : seriesvolume . Labels ,
} )
@ -1090,7 +1104,7 @@ func TestInstance_Volume(t *testing.T) {
From : 0 ,
Through : 1.1 * 1e3 , //milliseconds
Matchers : ` { log_stream=~".+"} ` ,
Limit : 3 ,
Limit : 5 ,
TargetLabels : [ ] string { "host" , "job" } ,
AggregateBy : seriesvolume . Labels ,
} )