forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rhythm] Multiple fixes to block-builder consumption (grafana#4413)
* Multiple fixes to cycle consumption * fmt * happy now? * ups
- Loading branch information
Showing
9 changed files
with
265 additions
and
15 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,38 @@ | ||
package blockbuilder | ||
|
||
import "fmt" | ||
|
||
const ( | ||
kafkaCommitMetaV1 = 1 | ||
) | ||
|
||
// marshallCommitMeta generates the commit metadata string. | ||
// commitRecTs: timestamp of the record which was committed (and not the commit time). | ||
func marshallCommitMeta(commitRecTs int64) string { | ||
return fmt.Sprintf("%d,%d", kafkaCommitMetaV1, commitRecTs) | ||
} | ||
|
||
// unmarshallCommitMeta parses the commit metadata string. | ||
// commitRecTs: timestamp of the record which was committed (and not the commit time). | ||
func unmarshallCommitMeta(s string) (commitRecTs int64, err error) { | ||
if s == "" { | ||
return | ||
} | ||
var ( | ||
version int | ||
metaStr string | ||
) | ||
_, err = fmt.Sscanf(s, "%d,%s", &version, &metaStr) | ||
if err != nil { | ||
return 0, fmt.Errorf("invalid commit metadata format: parse meta version: %w", err) | ||
} | ||
|
||
if version != kafkaCommitMetaV1 { | ||
return 0, fmt.Errorf("unsupported commit meta version %d", version) | ||
} | ||
_, err = fmt.Sscanf(metaStr, "%d", &commitRecTs) | ||
if err != nil { | ||
return 0, fmt.Errorf("invalid commit metadata format: %w", err) | ||
} | ||
return | ||
} |
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,47 @@ | ||
package blockbuilder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMarshallCommitMeta(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
commitRecTs int64 | ||
expectedMeta string | ||
}{ | ||
{"ValidTimestamp", 1627846261, "1,1627846261"}, | ||
{"ZeroTimestamp", 0, "1,0"}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
meta := marshallCommitMeta(tc.commitRecTs) | ||
assert.Equal(t, tc.expectedMeta, meta, "expected: %s, got: %s", tc.expectedMeta, meta) | ||
}) | ||
} | ||
} | ||
|
||
func TestUnmarshallCommitMeta(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
meta string | ||
expectedTs int64 | ||
expectedError bool | ||
}{ | ||
{"ValidMeta", "1,1627846261", 1627846261, false}, | ||
{"InvalidMetaFormat", "1,invalid", 0, true}, | ||
{"UnsupportedVersion", "2,1627846261", 0, true}, | ||
{"EmptyMeta", "", 0, false}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
ts, err := unmarshallCommitMeta(tc.meta) | ||
assert.Equal(t, tc.expectedError, err != nil, "expected error: %v, got: %v", tc.expectedError, err) | ||
assert.Equal(t, tc.expectedTs, ts, "expected: %d, got: %d", tc.expectedTs, ts) | ||
}) | ||
} | ||
} |
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,64 @@ | ||
package blockbuilder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/grafana/tempo/tempodb/backend" | ||
"github.com/grafana/tempo/tempodb/encoding" | ||
"github.com/grafana/tempo/tempodb/encoding/common" | ||
v2 "github.com/grafana/tempo/tempodb/encoding/v2" | ||
"github.com/grafana/tempo/tempodb/encoding/vparquet4" | ||
"github.com/grafana/tempo/tempodb/wal" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfig_validate(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cfg Config | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "ValidConfig", | ||
cfg: Config{ | ||
BlockConfig: BlockConfig{ | ||
BlockCfg: common.BlockConfig{ | ||
Version: encoding.LatestEncoding().Version(), | ||
IndexDownsampleBytes: 1, | ||
IndexPageSizeBytes: 1, | ||
BloomFP: 0.1, | ||
BloomShardSizeBytes: 1, | ||
DedicatedColumns: backend.DedicatedColumns{ | ||
{Scope: backend.DedicatedColumnScopeResource, Name: "foo", Type: backend.DedicatedColumnTypeString}, | ||
}, | ||
}, | ||
}, | ||
WAL: wal.Config{ | ||
Version: encoding.LatestEncoding().Version(), | ||
}, | ||
}, | ||
expectedErr: false, | ||
}, | ||
{ | ||
name: "InvalidBlockConfig", | ||
cfg: Config{ | ||
BlockConfig: BlockConfig{ | ||
BlockCfg: common.BlockConfig{ | ||
Version: vparquet4.VersionString, | ||
IndexDownsampleBytes: 0, | ||
}, | ||
}, | ||
WAL: wal.Config{ | ||
Version: v2.VersionString, | ||
}, | ||
}, | ||
expectedErr: true, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := tc.cfg.Validate() | ||
assert.Equal(t, tc.expectedErr, err != nil, "unexpected error: %v", err) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.