-
Notifications
You must be signed in to change notification settings - Fork 2
[LFXV2-1187] Add post-indexing NATS domain events #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| // Package contracts defines the interfaces and contracts for the domain layer of the LFX indexer service. | ||
| package contracts | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/linuxfoundation/lfx-v2-indexer-service/pkg/constants" | ||
| ) | ||
|
|
||
| // IndexingEvent is the NATS event payload published after a successful OpenSearch write. | ||
| // It is emitted on subjects of the form lfx.{object_type}.{action} | ||
| // (e.g., lfx.project.created, lfx.committee.deleted). | ||
| type IndexingEvent struct { | ||
| // DocumentID is the canonical OpenSearch document reference in the form | ||
| // "object_type:object_id" (e.g., "project:abc-123"). | ||
| DocumentID string `json:"document_id"` | ||
|
|
||
| // ObjectID is the identifier of the object (e.g., "abc-123"). | ||
| ObjectID string `json:"object_id"` | ||
|
|
||
| // ObjectType is the type of the object (e.g., "project", "committee"). | ||
| ObjectType string `json:"object_type"` | ||
|
|
||
| // Action is the canonical past-tense action that produced this event | ||
| // (e.g., "created", "updated", "deleted"). | ||
| Action constants.MessageAction `json:"action"` | ||
|
|
||
| // Body is the full TransactionBody that was written to OpenSearch. | ||
| Body *TransactionBody `json:"body"` | ||
|
|
||
| // Timestamp is the UTC time at which the indexing operation completed. | ||
| Timestamp time.Time `json:"timestamp"` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,10 +9,17 @@ import "time" | |
| // NATS subject prefixes (preserved from existing) | ||
| // These constants define the protocol format for NATS message subjects | ||
| const ( | ||
| IndexPrefix = "lfx.index." // V2 message prefix | ||
| FromV1Prefix = "lfx.v1.index." // V1 message prefix | ||
| IndexPrefix = "lfx.index." // V2 message prefix | ||
| FromV1Prefix = "lfx.v1.index." // V1 message prefix | ||
| EventSubjectPrefix = "lfx." // Post-indexing domain event prefix: lfx.{object_type}.{action} | ||
| ) | ||
|
|
||
| // BuildEventSubject constructs the NATS subject for a post-indexing domain event. | ||
| // Format: lfx.{object_type}.{action} (e.g., "lfx.project.created", "lfx.committee.deleted"). | ||
| func BuildEventSubject(objectType string, action MessageAction) string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a blocker at all, but it seems a bit odd to see functions like this in the constant package. In the future, we might want to create another folder here (with a meaningful name, like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, I agree we can make this update. |
||
| return EventSubjectPrefix + objectType + "." + string(action) | ||
| } | ||
|
|
||
| // NATS subjects (professional expansion) | ||
| const ( | ||
| ProjectSubject = IndexPrefix + "project" // V2 project messages | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package constants_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/linuxfoundation/lfx-v2-indexer-service/pkg/constants" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestBuildEventSubject(t *testing.T) { | ||
| tests := []struct { | ||
| objectType string | ||
| action constants.MessageAction | ||
| expected string | ||
| }{ | ||
| {constants.ObjectTypeProject, constants.ActionCreated, "lfx.project.created"}, | ||
| {constants.ObjectTypeProject, constants.ActionUpdated, "lfx.project.updated"}, | ||
| {constants.ObjectTypeProject, constants.ActionDeleted, "lfx.project.deleted"}, | ||
| {constants.ObjectTypeCommittee, constants.ActionCreated, "lfx.committee.created"}, | ||
| {constants.ObjectTypeMeeting, constants.ActionDeleted, "lfx.meeting.deleted"}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.expected, func(t *testing.T) { | ||
| got := constants.BuildEventSubject(tt.objectType, tt.action) | ||
| assert.Equal(t, tt.expected, got) | ||
| }) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.