fix(eventstore): precise decimal (#8527)

# Which Problems Are Solved

Float64 which was used for the event.Position field is [not precise in
go and gets rounded](https://github.com/golang/go/issues/47300). This
can lead to unprecies position tracking of events and therefore
projections especially on cockcoachdb as the position used there is a
big number.

example of a unprecies position:
exact: 1725257931223002628
float64: 1725257931223002624.000000

# How the Problems Are Solved

The float64 was replaced by
[github.com/jackc/pgx-shopspring-decimal](https://github.com/jackc/pgx-shopspring-decimal).

# Additional Changes

Correct behaviour of makefile for load tests.
Rename `latestSequence`-queries to `latestPosition`
This commit is contained in:
Silvan
2024-09-06 11:19:19 +02:00
committed by GitHub
parent 2981ff04da
commit b522588d98
47 changed files with 319 additions and 215 deletions

View File

@@ -9,6 +9,7 @@ import (
"time"
"github.com/jackc/pgx/v5/pgconn"
"github.com/shopspring/decimal"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/api/service"
@@ -390,7 +391,7 @@ func (repo *testPusher) Push(ctx context.Context, commands ...Command) (events [
type testQuerier struct {
events []Event
sequence float64
sequence decimal.Decimal
instances []string
err error
t *testing.T
@@ -423,9 +424,9 @@ func (repo *testQuerier) FilterToReducer(ctx context.Context, searchQuery *Searc
return nil
}
func (repo *testQuerier) LatestSequence(ctx context.Context, queryFactory *SearchQueryBuilder) (float64, error) {
func (repo *testQuerier) LatestPosition(ctx context.Context, queryFactory *SearchQueryBuilder) (decimal.Decimal, error) {
if repo.err != nil {
return 0, repo.err
return decimal.Decimal{}, repo.err
}
return repo.sequence, nil
}
@@ -1055,7 +1056,7 @@ func TestEventstore_FilterEvents(t *testing.T) {
}
}
func TestEventstore_LatestSequence(t *testing.T) {
func TestEventstore_LatestPosition(t *testing.T) {
type args struct {
query *SearchQueryBuilder
}
@@ -1075,7 +1076,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
name: "no events",
args: args{
query: &SearchQueryBuilder{
columns: ColumnsMaxSequence,
columns: ColumnsMaxPosition,
queries: []*SearchQuery{
{
builder: &SearchQueryBuilder{},
@@ -1098,7 +1099,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
name: "repo error",
args: args{
query: &SearchQueryBuilder{
columns: ColumnsMaxSequence,
columns: ColumnsMaxPosition,
queries: []*SearchQuery{
{
builder: &SearchQueryBuilder{},
@@ -1121,7 +1122,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
name: "found events",
args: args{
query: &SearchQueryBuilder{
columns: ColumnsMaxSequence,
columns: ColumnsMaxPosition,
queries: []*SearchQuery{
{
builder: &SearchQueryBuilder{},
@@ -1147,7 +1148,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
querier: tt.fields.repo,
}
_, err := es.LatestSequence(context.Background(), tt.args.query)
_, err := es.LatestPosition(context.Background(), tt.args.query)
if (err != nil) != tt.res.wantErr {
t.Errorf("Eventstore.aggregatesToEvents() error = %v, wantErr %v", err, tt.res.wantErr)
}