From 02a5d8c4e4bff6adddb463709ea49c90fee034f2 Mon Sep 17 00:00:00 2001 From: GLYASAI Date: Fri, 23 Jul 2021 13:23:58 +0800 Subject: [PATCH 1/2] support multiple probes --- api/handler/service.go | 4 +++- api/model/component.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/api/handler/service.go b/api/handler/service.go index 69621f46f..273a6e124 100644 --- a/api/handler/service.go +++ b/api/handler/service.go @@ -2712,7 +2712,9 @@ func (s *ServiceAction) SyncComponentProbes(tx *gorm.DB, components []*api_model ) for _, component := range components { componentIDs = append(componentIDs, component.ComponentBase.ComponentID) - probes = append(probes, component.Probe.DbModel(component.ComponentBase.ComponentID)) + for _, probe := range component.Probes { + probes = append(probes, probe.DbModel(component.ComponentBase.ComponentID)) + } } if err := db.GetManager().ServiceProbeDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil { return err diff --git a/api/model/component.go b/api/model/component.go index d678a8f1e..5a6a6e724 100644 --- a/api/model/component.go +++ b/api/model/component.go @@ -243,7 +243,7 @@ type Component struct { Ports []TenantServicesPort `json:"ports"` Relations []TenantComponentRelation `json:"relations"` Envs []ComponentEnv `json:"envs"` - Probe ServiceProbe `json:"probe"` + Probes []ServiceProbe `json:"probes"` AppConfigGroupRels []AppConfigGroupRelations `json:"app_config_groups"` Labels []ComponentLabel `json:"labels"` Plugins []ComponentPlugin `json:"plugins"` From fc1aa11569260ce0a632c670d7531dda77b2a214 Mon Sep 17 00:00:00 2001 From: GLYASAI Date: Fri, 23 Jul 2021 16:49:12 +0800 Subject: [PATCH 2/2] dedup probe by mode --- api/handler/service.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/handler/service.go b/api/handler/service.go index 273a6e124..392df0f08 100644 --- a/api/handler/service.go +++ b/api/handler/service.go @@ -2712,8 +2712,14 @@ func (s *ServiceAction) SyncComponentProbes(tx *gorm.DB, components []*api_model ) for _, component := range components { componentIDs = append(componentIDs, component.ComponentBase.ComponentID) + modes := make(map[string]struct{}) for _, probe := range component.Probes { + _, ok := modes[probe.Mode] + if ok { + continue + } probes = append(probes, probe.DbModel(component.ComponentBase.ComponentID)) + modes[probe.Mode] = struct{}{} } } if err := db.GetManager().ServiceProbeDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {