feat: update d7y.io/api/v2 to v2.1.42 and report scheduler config to … (#4214)

feat: update d7y.io/api/v2 to v2.1.42 and report scheduler config to manager

Signed-off-by: chlins <chlins.zhang@gmail.com>
This commit is contained in:
Chlins Zhang 2025-07-17 13:57:26 +08:00 committed by GitHub
parent 93dc9ef852
commit 364530212d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 3 deletions

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.23.8
require (
cloud.google.com/go/storage v1.50.0
d7y.io/api/v2 v2.1.39
d7y.io/api/v2 v2.1.42
github.com/MysteriousPotato/go-lockable v1.0.0
github.com/Showmax/go-fqdn v1.0.0
github.com/VividCortex/mysqlerr v1.0.0

4
go.sum
View File

@ -63,8 +63,8 @@ cloud.google.com/go/storage v1.50.0 h1:3TbVkzTooBvnZsk7WaAQfOsNrdoM8QHusXA1cpk6Q
cloud.google.com/go/storage v1.50.0/go.mod h1:l7XeiD//vx5lfqE3RavfmU9yvk5Pp0Zhcv482poyafY=
cloud.google.com/go/trace v1.11.2 h1:4ZmaBdL8Ng/ajrgKqY5jfvzqMXbrDcBsUGXOT9aqTtI=
cloud.google.com/go/trace v1.11.2/go.mod h1:bn7OwXd4pd5rFuAnTrzBuoZ4ax2XQeG3qNgYmfCy0Io=
d7y.io/api/v2 v2.1.39 h1:BxbccbEUooXuCr8aqRr5hNQONFdL7DOWo5pz2CnBg/0=
d7y.io/api/v2 v2.1.39/go.mod h1:5DPjID9MNDgw0mOqf49KF6Mho4x2v+C3uKmWWQYCWUs=
d7y.io/api/v2 v2.1.42 h1:JLBWPcVvTqClLedfRipHSIVkxEJFPQ5Mz1vnNo1Sklw=
d7y.io/api/v2 v2.1.42/go.mod h1:IbhylQWRkqRka+oUl73Fzz331fHFIAwS2m4cMNpFWdk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=

View File

@ -470,6 +470,13 @@ func (s *managerServerV2) UpdateScheduler(ctx context.Context, req *managerv2.Up
schedulerFeatures = req.GetFeatures()
}
var schedulerConfig models.JSONMap
if len(req.Config) > 0 {
if err := json.Unmarshal(req.Config, &schedulerConfig); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
}
if err := s.db.WithContext(ctx).Model(&scheduler).Updates(models.Scheduler{
IDC: req.GetIdc(),
Location: req.GetLocation(),
@ -478,6 +485,7 @@ func (s *managerServerV2) UpdateScheduler(ctx context.Context, req *managerv2.Up
SchedulerClusterID: uint(req.GetSchedulerClusterId()),
Features: schedulerFeatures,
LastKeepAliveAt: time.Now(),
Config: schedulerConfig,
}).Error; err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@ -516,6 +524,13 @@ func (s *managerServerV2) createScheduler(ctx context.Context, req *managerv2.Up
schedulerFeatures = req.GetFeatures()
}
var schedulerConfig models.JSONMap
if len(req.Config) > 0 {
if err := json.Unmarshal(req.Config, &schedulerConfig); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
}
scheduler := models.Scheduler{
Hostname: req.GetHostname(),
IDC: req.GetIdc(),
@ -525,6 +540,7 @@ func (s *managerServerV2) createScheduler(ctx context.Context, req *managerv2.Up
Features: schedulerFeatures,
SchedulerClusterID: uint(req.GetSchedulerClusterId()),
LastKeepAliveAt: time.Now(),
Config: schedulerConfig,
}
if err := s.db.WithContext(ctx).Create(&scheduler).Error; err != nil {

View File

@ -20,10 +20,12 @@ package announcer
import (
"context"
"encoding/json"
managerv2 "d7y.io/api/v2/pkg/apis/manager/v2"
logger "d7y.io/dragonfly/v2/internal/dflog"
managertypes "d7y.io/dragonfly/v2/manager/types"
managerclient "d7y.io/dragonfly/v2/pkg/rpc/manager/client"
"d7y.io/dragonfly/v2/scheduler/config"
)
@ -59,6 +61,14 @@ func New(cfg *config.Config, managerClient managerclient.V2, schedulerFeatures [
opt(a)
}
// Report scheduler configuration to manager.
config, err := json.Marshal(&managertypes.SchedulerConfig{
ManagerKeepAliveInterval: a.config.Manager.KeepAlive.Interval,
})
if err != nil {
return nil, err
}
// Register to manager.
if _, err := a.managerClient.UpdateScheduler(context.Background(), &managerv2.UpdateSchedulerRequest{
SourceType: managerv2.SourceType_SCHEDULER_SOURCE,
@ -69,6 +79,7 @@ func New(cfg *config.Config, managerClient managerclient.V2, schedulerFeatures [
Location: &a.config.Host.Location,
SchedulerClusterId: uint64(a.config.Manager.SchedulerClusterID),
Features: schedulerFeatures,
Config: config,
}); err != nil {
return nil, err
}

View File

@ -160,6 +160,7 @@ func TestAnnouncer_Serve(t *testing.T) {
time.Sleep(3 * time.Second)
},
mock: func(data []byte, m *managerclientmocks.MockV2MockRecorder) {
gomock.InOrder(
m.UpdateScheduler(gomock.Any(), gomock.Eq(&managerv2.UpdateSchedulerRequest{
SourceType: managerv2.SourceType_SCHEDULER_SOURCE,
@ -170,6 +171,7 @@ func TestAnnouncer_Serve(t *testing.T) {
Location: &mockLocation,
SchedulerClusterId: uint64(1),
Features: managertypes.DefaultSchedulerFeatures,
Config: []byte("{\"manager_keep_alive_interval\":50000000}"),
})).Times(1),
m.KeepAlive(gomock.Eq(50*time.Millisecond), gomock.Eq(&managerv2.KeepAliveRequest{
SourceType: managerv2.SourceType_SCHEDULER_SOURCE,
@ -244,6 +246,7 @@ func TestAnnouncer_announceToManager(t *testing.T) {
Location: &mockLocation,
SchedulerClusterId: uint64(1),
Features: managertypes.DefaultSchedulerFeatures,
Config: []byte("{\"manager_keep_alive_interval\":50000000}"),
})).Times(1),
m.KeepAlive(gomock.Eq(50*time.Millisecond), gomock.Eq(&managerv2.KeepAliveRequest{
SourceType: managerv2.SourceType_SCHEDULER_SOURCE,