-
Notifications
You must be signed in to change notification settings - Fork 63
Edit Instance Count Enabled #289
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
base: develop
Are you sure you want to change the base?
Changes from all commits
363041b
614d483
c3762fd
bb796ed
f380623
c7ee967
1aa8d32
19c0d77
0423a9e
9754fcb
b845141
2199ed2
8a8157a
340983e
8ecb0ea
649e89d
4ec6b12
1303975
7135c92
a07f6f2
16aeb6c
2968ade
a254d78
bac72ce
17f3abf
b83d40a
efcb9b6
9b9f087
57f1b94
d16a7f2
dec6fbc
f5993a1
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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "path" | ||
| "strings" | ||
| "time" | ||
|
|
||
|
|
@@ -13,7 +14,9 @@ import ( | |
| "github.com/Meesho/BharatMLStack/horizon/internal/repositories/sql/predatorconfig" | ||
| "github.com/Meesho/BharatMLStack/horizon/internal/repositories/sql/predatorrequest" | ||
| "github.com/rs/zerolog/log" | ||
| "google.golang.org/protobuf/encoding/prototext" | ||
| "gorm.io/gorm" | ||
| "github.com/Meesho/BharatMLStack/horizon/internal/predator/proto/protogen" | ||
| ) | ||
|
|
||
| func (p *Predator) processRequest(requestIdPayloadMap map[uint]*Payload, predatorRequestList []predatorrequest.PredatorRequest, req ApproveRequest) { | ||
|
|
@@ -191,6 +194,12 @@ func (p *Predator) processEditGCSCopyStage(requestIdPayloadMap map[uint]*Payload | |
| } else { | ||
| configBucket := pred.GcsConfigBucket | ||
| configPath := pred.GcsConfigBasePath | ||
| if configBucket != "" && configPath != "" && payload.MetaData.InstanceCount > 0 { | ||
| if err := p.updateInstanceCountInConfigSource(configBucket, configPath, modelName, payload.MetaData.InstanceCount); err != nil { | ||
| log.Error().Err(err).Msgf("Failed to update instance count in config-source for model %s", modelName) | ||
| return transferredGcsModelData, err | ||
| } | ||
| } | ||
|
Comment on lines
+197
to
+202
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. Config-source update lacks rollback on later failures. If the instance_count update succeeds but the subsequent GCS transfer / DB update / restart fails, the config-source stays mutated while the request is marked failed. Consider deferring this update until success or capturing the original config and restoring it on any downstream failure. π€ Prompt for AI Agents
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. Mutation is not harmful and rollback will cause more read writes. 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.
βοΈ Learnings added
|
||
| if err := p.GcsClient.TransferFolderWithSplitSources( | ||
| sourceBucket, sourceBasePath, configBucket, configPath, | ||
| sourceModelName, targetBucket, targetPath, modelName, | ||
|
|
@@ -212,6 +221,53 @@ func (p *Predator) processEditGCSCopyStage(requestIdPayloadMap map[uint]*Payload | |
| return transferredGcsModelData, nil | ||
| } | ||
|
|
||
| func (p *Predator) updateInstanceCountInConfigSource(bucket, basePath, modelName string, instanceCount int) error { | ||
| if modelName == "" { | ||
| return fmt.Errorf("model name is empty, required to update instance count in config-source") | ||
| } | ||
|
|
||
| configPath := path.Join(basePath, modelName, configFile) | ||
| configData, err := p.GcsClient.ReadFile(bucket, configPath) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to read config.pbtxt from config-source for model %s: %w", modelName, err) | ||
| } | ||
|
|
||
| var modelConfig protogen.ModelConfig | ||
| if err := prototext.Unmarshal(configData, &modelConfig); err != nil { | ||
| return fmt.Errorf("failed to parse config.pbtxt from config-source for model %s: %w", modelName, err) | ||
| } | ||
| if len(modelConfig.InstanceGroup) == 0 { | ||
| return fmt.Errorf("%s (model %s)", errNoInstanceGroup, modelName) | ||
| } | ||
|
|
||
| currentCount := modelConfig.InstanceGroup[0].Count | ||
| if currentCount == int32(instanceCount) { | ||
| log.Info(). | ||
| Str("model", modelName). | ||
| Int("instance_count", instanceCount). | ||
| Msg("instance_count unchanged, skipping config update") | ||
| return nil | ||
| } | ||
|
|
||
| modelConfig.InstanceGroup[0].Count = int32(instanceCount) | ||
|
|
||
| opts := prototext.MarshalOptions{ | ||
| Multiline: true, | ||
| Indent: " ", | ||
| } | ||
|
|
||
| newConfigData, err := opts.Marshal(&modelConfig) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal config.pbtxt for model %s: %w", modelName, err) | ||
| } | ||
| if err := p.GcsClient.UploadFile(bucket, configPath, newConfigData); err != nil { | ||
| return fmt.Errorf("failed to upload config.pbtxt to config-source for model %s: %w", modelName, err) | ||
| } | ||
|
|
||
| log.Info().Msgf("Updated instance_count to %d in config-source for model %s", instanceCount, modelName) | ||
| return nil | ||
| } | ||
|
|
||
| // processEditDBUpdateStage updates predator config for edit approval | ||
| // This updates the existing predator config with new config.pbtxt and metadata.json changes | ||
| func (p *Predator) processEditDBUpdateStage(requestIdPayloadMap map[uint]*Payload, predatorRequestList []predatorrequest.PredatorRequest, approvedBy string) error { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.