Skip to content
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

feat: raft event logging #4292

Merged
merged 1 commit into from
Feb 4, 2025
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: 2 additions & 0 deletions backend/schemaservice/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

// ApplyEvent applies an event to the schema state
func (r SchemaState) ApplyEvent(ctx context.Context, event schema.Event) error {
logger := log.FromContext(ctx)
logger.Debugf("Applying Raft event %s", event.DebugString())
if err := event.Validate(); err != nil {
return fmt.Errorf("invalid event: %w", err)
}
Expand Down
70 changes: 70 additions & 0 deletions common/schema/events.go → common/schema/raftevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
type Event interface {
event()
Validate() error
// DebugString returns a string representation of the event for debugging purposes
DebugString() string
}

// deployment events
Expand Down Expand Up @@ -43,6 +45,10 @@ type DeploymentCreatedEvent struct {
Changeset *key.Changeset `protobuf:"3"`
}

func (r *DeploymentCreatedEvent) DebugString() string {
return fmt.Sprintf("DeploymentCreatedEvent{key: %s, changeset: %s}", r.Key.String(), r.Changeset.String())
}

func (r *DeploymentCreatedEvent) event() {}

func (r *DeploymentCreatedEvent) Validate() error {
Expand All @@ -59,6 +65,10 @@ type DeploymentSchemaUpdatedEvent struct {
Changeset key.Changeset `protobuf:"3"`
}

func (r *DeploymentSchemaUpdatedEvent) DebugString() string {
return fmt.Sprintf("DeploymentSchemaUpdatedEvent{key: %s, changeset: %s}", r.Key.String(), r.Changeset.String())
}

func (r *DeploymentSchemaUpdatedEvent) event() {}

func (r *DeploymentSchemaUpdatedEvent) Validate() error {
Expand All @@ -72,6 +82,10 @@ type DeploymentReplicasUpdatedEvent struct {
Changeset *key.Changeset `protobuf:"3"`
}

func (r *DeploymentReplicasUpdatedEvent) DebugString() string {
return fmt.Sprintf("DeploymentReplicasUpdatedEvent{key: %s, changeset: %s, replicas: %d}", r.Key.String(), r.Changeset.String(), r.Replicas)
}

func (r *DeploymentReplicasUpdatedEvent) event() {}

func (r *DeploymentReplicasUpdatedEvent) Validate() error {
Expand All @@ -86,6 +100,10 @@ type DeploymentActivatedEvent struct {
Changeset *key.Changeset `protobuf:"4"`
}

func (r *DeploymentActivatedEvent) DebugString() string {
return fmt.Sprintf("DeploymentActivatedEvent{key: %s, changeset: %s, minReplicas: %d}", r.Key.String(), r.Changeset.String(), r.MinReplicas)
}

func (r *DeploymentActivatedEvent) event() {}

func (r *DeploymentActivatedEvent) Validate() error {
Expand All @@ -99,6 +117,10 @@ type DeploymentDeactivatedEvent struct {
Changeset *key.Changeset `protobuf:"3"`
}

func (r *DeploymentDeactivatedEvent) DebugString() string {
return fmt.Sprintf("DeploymentDeactivatedEvent{key: %s, changeset: %s, moduleRemoved: %v}", r.Key.String(), r.Changeset.String(), r.ModuleRemoved)
}

func (r *DeploymentDeactivatedEvent) event() {}

func (r *DeploymentDeactivatedEvent) Validate() error {
Expand All @@ -113,6 +135,10 @@ type VerbRuntimeEvent struct {
Subscription optional.Option[VerbRuntimeSubscription] `protobuf:"4"`
}

func (e *VerbRuntimeEvent) DebugString() string {
return fmt.Sprintf("VerbRuntimeEvent{module: %s, changeset: %s, id: %v, subscription: %v}", e.Module, e.Changeset.String(), e.ID, e.Subscription)
}

func (e *VerbRuntimeEvent) event() {}

func (e *VerbRuntimeEvent) Validate() error {
Expand All @@ -127,6 +153,10 @@ type TopicRuntimeEvent struct {
Payload *TopicRuntime `protobuf:"4"`
}

func (e *TopicRuntimeEvent) DebugString() string {
return fmt.Sprintf("TopicRuntimeEvent{module: %s, changeset: %s, id: %v, payload: %v}", e.Module, e.Changeset.String(), e.ID, e.Payload)
}

func (e *TopicRuntimeEvent) event() {}

func (e *TopicRuntimeEvent) Validate() error {
Expand All @@ -141,6 +171,10 @@ type DatabaseRuntimeEvent struct {
Connections *DatabaseRuntimeConnections `protobuf:"4"`
}

func (e *DatabaseRuntimeEvent) DebugString() string {
return fmt.Sprintf("DatabaseRuntimeEvent{module: %s, changeset: %s, id: %v, connections: %v}", e.Module, e.Changeset.String(), e.ID, e.Connections)
}

func (e *DatabaseRuntimeEvent) event() {}

func (e *DatabaseRuntimeEvent) Validate() error {
Expand All @@ -156,6 +190,10 @@ type ModuleRuntimeEvent struct {
Deployment optional.Option[ModuleRuntimeDeployment] `protobuf:"5"`
}

func (e *ModuleRuntimeEvent) DebugString() string {
return fmt.Sprintf("ModuleRuntimeEvent{deployment: %s, changeset: %s, deployment %v}", e.DeploymentKey.String(), e.Changeset.String(), e.Deployment)
}

func (e *ModuleRuntimeEvent) event() {}

func (e *ModuleRuntimeEvent) Validate() error {
Expand All @@ -167,6 +205,18 @@ type ChangesetCreatedEvent struct {
Changeset *Changeset `protobuf:"1"`
}

func (e *ChangesetCreatedEvent) DebugString() string {
ret := fmt.Sprintf("ChangesetCreatedEvent{key: %s", e.Changeset.Key.String())
for _, m := range e.Changeset.Modules {
if m.Runtime == nil || m.Runtime.Deployment == nil {
ret += fmt.Sprintf(", invalid module: %s", m.Name)
} else {
ret += fmt.Sprintf(", deployment: %s", m.Runtime.Deployment.DeploymentKey.String())
}
}
return ret + "}"
}

func (e *ChangesetCreatedEvent) event() {}

func (e *ChangesetCreatedEvent) Validate() error {
Expand All @@ -181,6 +231,10 @@ type ChangesetPreparedEvent struct {
Key key.Changeset `protobuf:"1"`
}

func (e *ChangesetPreparedEvent) DebugString() string {
return fmt.Sprintf("ChangesetPreparedEvent{changeset: %s}", e.Key.String())
}

func (e *ChangesetPreparedEvent) event() {}

func (e *ChangesetPreparedEvent) Validate() error {
Expand All @@ -192,6 +246,10 @@ type ChangesetCommittedEvent struct {
Key key.Changeset `protobuf:"1"`
}

func (e *ChangesetCommittedEvent) DebugString() string {
return fmt.Sprintf("ChangesetCommittedEvent{changeset: %s}", e.Key.String())
}

func (e *ChangesetCommittedEvent) event() {}

func (e *ChangesetCommittedEvent) Validate() error {
Expand All @@ -203,6 +261,10 @@ type ChangesetDrainedEvent struct {
Key key.Changeset `protobuf:"1"`
}

func (e *ChangesetDrainedEvent) DebugString() string {
return fmt.Sprintf("ChangesetDrainedEvent{changeset: %s}", e.Key.String())
}

func (e *ChangesetDrainedEvent) event() {}

func (e *ChangesetDrainedEvent) Validate() error {
Expand All @@ -214,6 +276,10 @@ type ChangesetFinalizedEvent struct {
Key key.Changeset `protobuf:"1"`
}

func (e *ChangesetFinalizedEvent) DebugString() string {
return fmt.Sprintf("ChangesetFinalizedEvent{changeset: %s}", e.Key.String())
}

func (e *ChangesetFinalizedEvent) event() {}

func (e *ChangesetFinalizedEvent) Validate() error {
Expand All @@ -226,6 +292,10 @@ type ChangesetFailedEvent struct {
Error string `protobuf:"2"`
}

func (e *ChangesetFailedEvent) DebugString() string {
return fmt.Sprintf("ChangesetFailedEvent{changeset: %s, Error: %s}", e.Key.String(), e.Error)
}

func (e *ChangesetFailedEvent) event() {}

func (e *ChangesetFailedEvent) Validate() error {
Expand Down
2 changes: 1 addition & 1 deletion internal/routing/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func extractRoutes(ctx context.Context, sch *schema.Schema) RouteView {
}
rt := module.Runtime.Deployment
if rt.Endpoint == "" {
logger.Debugf("Skipping route for %s/%s as it is not ready yet", module.Name, rt.DeploymentKey)
logger.Tracef("Skipping route for %s/%s as it is not ready yet", module.Name, rt.DeploymentKey)
continue
}
u, err := url.Parse(rt.Endpoint)
Expand Down
Loading