Skip to content

Commit

Permalink
Merge pull request #1076 from threefoldtech/development_proxy_fixes
Browse files Browse the repository at this point in the history
drop node_gpu_pkey constraint
  • Loading branch information
Omarabdul3ziz authored Jun 9, 2024
2 parents 534ca6b + 281a4fc commit 41584c7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion grid-proxy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Check `/version` on any instance to know the version.

## Releases

### v0.15.8
### v0.15.9

---

Expand Down
2 changes: 1 addition & 1 deletion grid-proxy/charts/gridproxy/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ version: 1.0.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.15.8
appVersion: 0.15.9

# make sure to update the changelog with the changes in this release
12 changes: 7 additions & 5 deletions grid-proxy/internal/explorer/db/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,25 @@ func (d *PostgresDatabase) GetLastUpsertsTimestamp() (types.IndexersState, error
}

func (d *PostgresDatabase) Initialize() error {
err := d.gormDB.AutoMigrate(
if err := d.gormDB.AutoMigrate(
&types.NodeGPU{},
&types.HealthReport{},
&types.Dmi{},
&types.Speed{},
&types.HasIpv6{},
&types.NodesWorkloads{},
)
if err != nil {
); err != nil {
return errors.Wrap(err, "failed to migrate indexer tables")
}

err = d.gormDB.Exec(setupFile).Error
if err != nil {
if err := d.gormDB.Exec(setupFile).Error; err != nil {
return errors.Wrap(err, "failed to setup cache tables")
}

if err := d.gormDB.Exec(`ALTER TABLE node_gpu DROP CONSTRAINT IF EXISTS node_gpu_pkey;`).Error; err != nil {
return errors.Wrap(err, "failed to drop the node_gpu_pkey constraint")
}

return nil
}

Expand Down
15 changes: 15 additions & 0 deletions grid-proxy/internal/indexer/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (w *HealthWork) Get(ctx context.Context, rmb *peer.RpcClient, twinId uint32
}

func (w *HealthWork) Upsert(ctx context.Context, db db.Database, batch []types.HealthReport) error {
// to prevent having multiple data for the same twin from different finders
batch = removeDuplicates(batch)
return db.UpsertNodeHealth(ctx, batch)
}

Expand All @@ -57,3 +59,16 @@ func getHealthReport(response interface{}, err error, twinId uint32) types.Healt
report.Healthy = true
return report
}

func removeDuplicates(reports []types.HealthReport) []types.HealthReport {
seen := make(map[uint32]bool)
result := []types.HealthReport{}
for _, report := range reports {
if _, ok := seen[report.NodeTwinId]; !ok {
seen[report.NodeTwinId] = true
result = append(result, report)
}
}

return result
}

0 comments on commit 41584c7

Please sign in to comment.