Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/99designs/gqlgen v0.17.86
github.com/ClickHouse/clickhouse-go/v2 v2.43.0
github.com/DIMO-Network/clickhouse-infra v0.0.7
github.com/DIMO-Network/cloudevent v0.2.5
github.com/DIMO-Network/cloudevent v0.2.7
github.com/DIMO-Network/server-garage v0.0.7
github.com/DIMO-Network/shared v1.1.7
github.com/DIMO-Network/token-exchange-api v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7Oputl
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/DIMO-Network/clickhouse-infra v0.0.7 h1:TAsjkFFKu3D5Xg6dwBcRBryjCVSlXsNjVbTwJ4UDlTg=
github.com/DIMO-Network/clickhouse-infra v0.0.7/go.mod h1:XS80lhSJNWBWGgZ+m4j7++zFj1wAXfmtV2gJfhGlabQ=
github.com/DIMO-Network/cloudevent v0.2.5 h1:3s6ZKtBXHYy0ujMYBdOBF9uJAc5C+EKEF7/SToW2cJA=
github.com/DIMO-Network/cloudevent v0.2.5/go.mod h1:zFG6pf7ejwC0y3//mHpISDHR/blsSz8Lew2c4ebc8Lw=
github.com/DIMO-Network/cloudevent v0.2.7 h1:/cgFhUcWcliZYrmITkB8oIZb+zDhZvYNxWVGS2D3894=
github.com/DIMO-Network/cloudevent v0.2.7/go.mod h1:I/9NcpMozV5Fw194WimhbkAsJtKVZf5UKYJ9hgc8Cdg=
github.com/DIMO-Network/server-garage v0.0.7 h1:kOBVyOtIbxa1x9pAf1epABTb9l/U3khf0PwUaHeHiKs=
github.com/DIMO-Network/server-garage v0.0.7/go.mod h1:7DFor8MMJ8fLv9EB16Z5LrN+ftW3qeIk+swpkT7F2cU=
github.com/DIMO-Network/shared v1.1.7 h1:5Ex8bZ6BpOjcLj4u7n5Kih1Ho6b9BVJsKpKn4iU2EaM=
Expand Down
3 changes: 3 additions & 0 deletions internal/graph/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestIndexToModel(t *testing.T) {
Type: "dimo.status",
DataContentType: "application/json",
DataVersion: "r/v0/s",
RawEventID: "raw-event-123",
},
Data: eventrepo.ObjectInfo{Key: "s3://bucket/key"},
}
Expand All @@ -33,6 +34,7 @@ func TestIndexToModel(t *testing.T) {
assert.Equal(t, "dimo.status", out.Header.Type)
assert.Equal(t, "application/json", out.Header.DataContentType)
assert.Equal(t, "r/v0/s", out.Header.DataVersion)
assert.Equal(t, "raw-event-123", out.Header.RawEventID)
assert.Equal(t, "s3://bucket/key", out.IndexKey)
})

Expand All @@ -51,5 +53,6 @@ func TestIndexToModel(t *testing.T) {
assert.Empty(t, out.Header.DataContentType)
assert.Empty(t, out.Header.DataVersion)
assert.Empty(t, out.Header.Signature)
assert.Empty(t, out.Header.RawEventID)
})
}
43 changes: 43 additions & 0 deletions internal/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions pkg/eventrepo/event_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ func TestGetEventWithAllHeaderFields(t *testing.T) {
DataVersion: dataType,
SpecVersion: cloudevent.SpecVersion,
Signature: "0x1234567890",
RawEventID: "raw-event-id-123",
Tags: []string{"tests.tag1", "tests.tag2"},
Extras: map[string]any{
"extraField": "extra-value",
Expand Down Expand Up @@ -458,6 +459,7 @@ func TestGetEventWithAllHeaderFields(t *testing.T) {
assert.Equal(t, fullHeaderEvent.DataVersion, retrievedEvent.DataVersion, "DataVersion mismatch")
assert.Equal(t, cloudevent.SpecVersion, retrievedEvent.SpecVersion, "SpecVersion mismatch")
assert.Equal(t, fullHeaderEvent.Signature, retrievedEvent.Signature, "Signature mismatch")
assert.Equal(t, fullHeaderEvent.RawEventID, retrievedEvent.RawEventID, "RawEventID mismatch")
assert.Equal(t, fullHeaderEvent.Tags, retrievedEvent.Tags, "Tags mismatch")

// Verify extras
Expand Down Expand Up @@ -492,6 +494,37 @@ func TestGetEventWithAllHeaderFields(t *testing.T) {
assert.Equal(t, "0x09876543210", retrievedEvent.Signature, "Signature field not set correctly")
assert.Nil(t, retrievedEvent.Extras["signature"], "Signature should not be in extras")
})

t.Run("retrieve event with raw event id that is originally in extras", func(t *testing.T) {
fullHeaderEvent3 := fullHeaderEvent
fullHeaderEvent3.Subject = eventDID2.String()
fullHeaderEvent3.RawEventID = ""
fullHeaderEvent3.Extras = map[string]any{
"raweventid": "raw-event-id-from-extras",
}
indexKey3 := insertTestData(t, ctx, conn, &fullHeaderEvent3)

mockS3Client.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) {
require.Equal(t, indexKey3, *params.Key)
return &s3.GetObjectOutput{
Body: io.NopCloser(bytes.NewReader(eventDataEnvelope)),
ContentLength: ref(int64(len(eventDataEnvelope))),
}, nil
},
)
opts := &grpc.SearchOptions{
DataVersion: &wrapperspb.StringValue{Value: dataType},
Subject: &wrapperspb.StringValue{Value: eventDID2.String()},
}

retrievedEvent, err := indexService.GetLatestCloudEvent(ctx, "test-bucket", opts)
require.NoError(t, err)

assert.Equal(t, fullHeaderEvent3.ID, retrievedEvent.ID, "ID mismatch")
assert.Equal(t, "raw-event-id-from-extras", retrievedEvent.RawEventID, "RawEventID field not set correctly")
assert.Nil(t, retrievedEvent.Extras["raweventid"], "RawEventID should not be in extras")
})
}

func ref[T any](x T) *T {
Expand Down
17 changes: 14 additions & 3 deletions pkg/grpc/cloudevent.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/grpc/cloudevent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ message CloudEventHeader {

// Signature hold the signature of the a cloudevent's data field.
string signature = 13;
}

// RawEventID links a parsed event to the backing raw event when present.
string raw_event_id = 14;
}
2 changes: 2 additions & 0 deletions pkg/grpc/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (c *CloudEventHeader) AsCloudEventHeader() cloudevent.CloudEventHeader {
DataVersion: c.GetDataVersion(),
Extras: extras,
Signature: c.GetSignature(),
RawEventID: c.GetRawEventId(),
Tags: TagsOrEmpty(c.GetTags()),
}
}
Expand Down Expand Up @@ -84,6 +85,7 @@ func CloudEventHeaderToProto(event *cloudevent.CloudEventHeader) *CloudEventHead
DataVersion: event.DataVersion,
Extras: extras,
Signature: event.Signature,
RawEventId: event.RawEventID,
Tags: TagsOrEmpty(event.Tags),
}
}
Expand Down
1 change: 1 addition & 0 deletions schema/base.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type CloudEventHeader {
dataversion: String
producer: String!
signature: String
raweventid: String
tags: [String!]!
}

Expand Down
Loading