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

Create and add deployment trace obj to datastore on event registering flow #5622

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

khanhtc1202
Copy link
Member

What this PR does:

as title

Why we need it:

While registering an event by pipette, we will create a DeploymentTrace object and store it in the datastore. The stored DeploymentTrace object contains information about the commit that triggered the event, which will be used in the DeploymentTrace feature UI.
Also, I updated the Event model to store trigger_commit_hash, which is the commit hash of the commit that triggers this event. This information will be used while handling the event (EventWatcher handling flow)

Which issue(s) this PR fixes:

Part of #5444

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 0% with 86 lines in your changes missing coverage. Please review.

Project coverage is 26.53%. Comparing base (6cf5097) to head (65ab759).

Files with missing lines Patch % Lines
pkg/datastore/deploymenttracestore.go 0.00% 51 Missing ⚠️
pkg/app/server/grpcapi/api.go 0.00% 33 Missing ⚠️
pkg/model/deployment_trace.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5622      +/-   ##
==========================================
- Coverage   26.56%   26.53%   -0.03%     
==========================================
  Files         475      477       +2     
  Lines       50582    50661      +79     
==========================================
+ Hits        13438    13444       +6     
- Misses      36081    36154      +73     
  Partials     1063     1063              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -103,3 +103,16 @@ CREATE TABLE IF NOT EXISTS DeploymentChain (
CreatedAt INT(11) GENERATED ALWAYS AS (data->>"$.created_at") STORED NOT NULL,
UpdatedAt INT(11) GENERATED ALWAYS AS (data->>"$.updated_at") STORED NOT NULL
) ENGINE=InnoDB;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is enable using MySQL as the datastore of ControlPlane; each time we have a new objStore (DeploymentTraceStore at this time), we need to create a new table in MySQL schema.

Comment on lines +26 to +70
type deploymentTraceCollection struct {
requestedBy Commander
}

func (d *deploymentTraceCollection) Kind() string {
return "DeploymentTrace"
}

func (d *deploymentTraceCollection) Factory() Factory {
return func() interface{} {
return &model.DeploymentTrace{}
}
}

func (d *deploymentTraceCollection) ListInUsedShards() []Shard {
return []Shard{
AgentShard,
}
}

func (d *deploymentTraceCollection) GetUpdatableShard() (Shard, error) {
switch d.requestedBy {
case PipedCommander:
return AgentShard, nil
default:
return "", ErrUnsupported
}
}

func (d *deploymentTraceCollection) Encode(entity interface{}) (map[Shard][]byte, error) {
const errFmt = "failed while encode Deployment Trace object: %s"

me, ok := entity.(*model.DeploymentTrace)
if !ok {
return nil, fmt.Errorf(errFmt, "type not matched")
}

data, err := json.Marshal(me)
if err != nil {
return nil, fmt.Errorf(errFmt, "unable to marshal entity data")
}
return map[Shard][]byte{
AgentShard: data,
}, nil
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to enable support filedb as db of the pipecd. I'm thinking about deprecated this filedb feature since we're not actively maintaining these parts. Let's ignore this while reviewing this PR 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant