mirror of https://github.com/status-im/consul.git
Merge pull request #7650 from hashicorp/dnephin/remove-id-init-methods
agent/structs: Remove ServiceID.Init and CheckID.Init
This commit is contained in:
commit
2cb7a25546
|
@ -2456,8 +2456,7 @@ func (a *Agent) addServiceInternal(req *addServiceRequest, snap map[structs.Chec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cid structs.CheckID
|
cid := structs.NewCheckID(types.CheckID(checkID), &service.EnterpriseMeta)
|
||||||
cid.Init(types.CheckID(checkID), &service.EnterpriseMeta)
|
|
||||||
existingChecks[cid] = true
|
existingChecks[cid] = true
|
||||||
|
|
||||||
name := chkType.Name
|
name := chkType.Name
|
||||||
|
@ -2531,8 +2530,7 @@ func (a *Agent) addServiceInternal(req *addServiceRequest, snap map[structs.Chec
|
||||||
|
|
||||||
// If a proxy service wishes to expose checks, check targets need to be rerouted to the proxy listener
|
// If a proxy service wishes to expose checks, check targets need to be rerouted to the proxy listener
|
||||||
// This needs to be called after chkTypes are added to the agent, to avoid being overwritten
|
// This needs to be called after chkTypes are added to the agent, to avoid being overwritten
|
||||||
var psid structs.ServiceID
|
psid := structs.NewServiceID(service.Proxy.DestinationServiceID, &service.EnterpriseMeta)
|
||||||
psid.Init(service.Proxy.DestinationServiceID, &service.EnterpriseMeta)
|
|
||||||
|
|
||||||
if service.Proxy.Expose.Checks {
|
if service.Proxy.Expose.Checks {
|
||||||
err := a.rerouteExposedChecks(psid, service.Address)
|
err := a.rerouteExposedChecks(psid, service.Address)
|
||||||
|
@ -2740,8 +2738,7 @@ func (a *Agent) removeServiceLocked(serviceID structs.ServiceID, persist bool) e
|
||||||
svc := a.State.Service(serviceID)
|
svc := a.State.Service(serviceID)
|
||||||
|
|
||||||
if svc != nil {
|
if svc != nil {
|
||||||
var psid structs.ServiceID
|
psid := structs.NewServiceID(svc.Proxy.DestinationServiceID, &svc.EnterpriseMeta)
|
||||||
psid.Init(svc.Proxy.DestinationServiceID, &svc.EnterpriseMeta)
|
|
||||||
a.resetExposedChecks(psid)
|
a.resetExposedChecks(psid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2784,8 +2781,7 @@ func (a *Agent) removeServiceLocked(serviceID structs.ServiceID, persist bool) e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) removeServiceSidecars(serviceID structs.ServiceID, persist bool) error {
|
func (a *Agent) removeServiceSidecars(serviceID structs.ServiceID, persist bool) error {
|
||||||
var sidecarSID structs.ServiceID
|
sidecarSID := structs.NewServiceID(a.sidecarServiceID(serviceID.ID), &serviceID.EnterpriseMeta)
|
||||||
sidecarSID.Init(a.sidecarServiceID(serviceID.ID), &serviceID.EnterpriseMeta)
|
|
||||||
if sidecar := a.State.Service(sidecarSID); sidecar != nil {
|
if sidecar := a.State.Service(sidecarSID); sidecar != nil {
|
||||||
// Double check that it's not just an ID collision and we actually added
|
// Double check that it's not just an ID collision and we actually added
|
||||||
// this from a sidecar.
|
// this from a sidecar.
|
||||||
|
@ -3138,8 +3134,7 @@ func (a *Agent) addCheck(check *structs.HealthCheck, chkType *structs.CheckType,
|
||||||
rpcReq.Token = token
|
rpcReq.Token = token
|
||||||
}
|
}
|
||||||
|
|
||||||
var aliasServiceID structs.ServiceID
|
aliasServiceID := structs.NewServiceID(chkType.AliasService, &check.EnterpriseMeta)
|
||||||
aliasServiceID.Init(chkType.AliasService, &check.EnterpriseMeta)
|
|
||||||
chkImpl := &checks.CheckAlias{
|
chkImpl := &checks.CheckAlias{
|
||||||
Notify: a.State,
|
Notify: a.State,
|
||||||
RPC: a.delegate,
|
RPC: a.delegate,
|
||||||
|
@ -3927,9 +3922,8 @@ func (a *Agent) unloadMetadata() {
|
||||||
|
|
||||||
// serviceMaintCheckID returns the ID of a given service's maintenance check
|
// serviceMaintCheckID returns the ID of a given service's maintenance check
|
||||||
func serviceMaintCheckID(serviceID structs.ServiceID) structs.CheckID {
|
func serviceMaintCheckID(serviceID structs.ServiceID) structs.CheckID {
|
||||||
var cid structs.CheckID
|
cid := types.CheckID(structs.ServiceMaintPrefix + serviceID.ID)
|
||||||
cid.Init(types.CheckID(structs.ServiceMaintPrefix+serviceID.ID), &serviceID.EnterpriseMeta)
|
return structs.NewCheckID(cid, &serviceID.EnterpriseMeta)
|
||||||
return cid
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnableServiceMaintenance will register a false health check against the given
|
// EnableServiceMaintenance will register a false health check against the given
|
||||||
|
|
|
@ -767,8 +767,7 @@ func (s *HTTPServer) AgentHealthServiceByID(resp http.ResponseWriter, req *http.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var sid structs.ServiceID
|
sid := structs.NewServiceID(serviceID, &entMeta)
|
||||||
sid.Init(serviceID, &entMeta)
|
|
||||||
|
|
||||||
if service := s.agent.State.Service(sid); service != nil {
|
if service := s.agent.State.Service(sid); service != nil {
|
||||||
if authz != nil && authz.ServiceRead(service.Service, &authzContext) != acl.Allow {
|
if authz != nil && authz.ServiceRead(service.Service, &authzContext) != acl.Allow {
|
||||||
|
@ -830,8 +829,7 @@ func (s *HTTPServer) AgentHealthServiceByName(resp http.ResponseWriter, req *htt
|
||||||
result := make([]api.AgentServiceChecksInfo, 0, 16)
|
result := make([]api.AgentServiceChecksInfo, 0, 16)
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
if service.Service == serviceName {
|
if service.Service == serviceName {
|
||||||
var sid structs.ServiceID
|
sid := structs.NewServiceID(service.ID, &entMeta)
|
||||||
sid.Init(service.ID, &entMeta)
|
|
||||||
|
|
||||||
scode, sstatus, healthChecks := agentHealthService(sid, s)
|
scode, sstatus, healthChecks := agentHealthService(sid, s)
|
||||||
serviceInfo := buildAgentService(service)
|
serviceInfo := buildAgentService(service)
|
||||||
|
|
|
@ -1224,9 +1224,8 @@ func (l *State) syncService(key structs.ServiceID) error {
|
||||||
// Given how the register API works, this info is also updated
|
// Given how the register API works, this info is also updated
|
||||||
// every time we sync a service.
|
// every time we sync a service.
|
||||||
l.nodeInfoInSync = true
|
l.nodeInfoInSync = true
|
||||||
var checkKey structs.CheckID
|
|
||||||
for _, check := range checks {
|
for _, check := range checks {
|
||||||
checkKey.Init(check.CheckID, &check.EnterpriseMeta)
|
checkKey := structs.NewCheckID(check.CheckID, &check.EnterpriseMeta)
|
||||||
l.checks[checkKey].InSync = true
|
l.checks[checkKey].InSync = true
|
||||||
}
|
}
|
||||||
l.logger.Info("Synced service", "service", key.String())
|
l.logger.Info("Synced service", "service", key.String())
|
||||||
|
@ -1236,9 +1235,8 @@ func (l *State) syncService(key structs.ServiceID) error {
|
||||||
// todo(fs): mark the service and the checks to be in sync to prevent excessive retrying before next full sync
|
// todo(fs): mark the service and the checks to be in sync to prevent excessive retrying before next full sync
|
||||||
// todo(fs): some backoff strategy might be a better solution
|
// todo(fs): some backoff strategy might be a better solution
|
||||||
l.services[key].InSync = true
|
l.services[key].InSync = true
|
||||||
var checkKey structs.CheckID
|
|
||||||
for _, check := range checks {
|
for _, check := range checks {
|
||||||
checkKey.Init(check.CheckID, &check.EnterpriseMeta)
|
checkKey := structs.NewCheckID(check.CheckID, &check.EnterpriseMeta)
|
||||||
l.checks[checkKey].InSync = true
|
l.checks[checkKey].InSync = true
|
||||||
}
|
}
|
||||||
accessorID := l.aclAccessorID(st)
|
accessorID := l.aclAccessorID(st)
|
||||||
|
@ -1272,8 +1270,7 @@ func (l *State) syncCheck(key structs.CheckID) error {
|
||||||
SkipNodeUpdate: l.nodeInfoInSync,
|
SkipNodeUpdate: l.nodeInfoInSync,
|
||||||
}
|
}
|
||||||
|
|
||||||
var serviceKey structs.ServiceID
|
serviceKey := structs.NewServiceID(c.Check.ServiceID, &key.EnterpriseMeta)
|
||||||
serviceKey.Init(c.Check.ServiceID, &key.EnterpriseMeta)
|
|
||||||
|
|
||||||
// Pull in the associated service if any
|
// Pull in the associated service if any
|
||||||
s := l.services[serviceKey]
|
s := l.services[serviceKey]
|
||||||
|
|
|
@ -1619,11 +1619,6 @@ type CheckID struct {
|
||||||
|
|
||||||
func NewCheckID(id types.CheckID, entMeta *EnterpriseMeta) CheckID {
|
func NewCheckID(id types.CheckID, entMeta *EnterpriseMeta) CheckID {
|
||||||
var cid CheckID
|
var cid CheckID
|
||||||
cid.Init(id, entMeta)
|
|
||||||
return cid
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cid *CheckID) Init(id types.CheckID, entMeta *EnterpriseMeta) {
|
|
||||||
cid.ID = id
|
cid.ID = id
|
||||||
if entMeta == nil {
|
if entMeta == nil {
|
||||||
entMeta = DefaultEnterpriseMeta()
|
entMeta = DefaultEnterpriseMeta()
|
||||||
|
@ -1631,6 +1626,7 @@ func (cid *CheckID) Init(id types.CheckID, entMeta *EnterpriseMeta) {
|
||||||
|
|
||||||
cid.EnterpriseMeta = *entMeta
|
cid.EnterpriseMeta = *entMeta
|
||||||
cid.EnterpriseMeta.Normalize()
|
cid.EnterpriseMeta.Normalize()
|
||||||
|
return cid
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringHash is used mainly to populate part of the filename of a check
|
// StringHash is used mainly to populate part of the filename of a check
|
||||||
|
@ -1649,11 +1645,6 @@ type ServiceID struct {
|
||||||
|
|
||||||
func NewServiceID(id string, entMeta *EnterpriseMeta) ServiceID {
|
func NewServiceID(id string, entMeta *EnterpriseMeta) ServiceID {
|
||||||
var sid ServiceID
|
var sid ServiceID
|
||||||
sid.Init(id, entMeta)
|
|
||||||
return sid
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sid *ServiceID) Init(id string, entMeta *EnterpriseMeta) {
|
|
||||||
sid.ID = id
|
sid.ID = id
|
||||||
if entMeta == nil {
|
if entMeta == nil {
|
||||||
entMeta = DefaultEnterpriseMeta()
|
entMeta = DefaultEnterpriseMeta()
|
||||||
|
@ -1661,6 +1652,7 @@ func (sid *ServiceID) Init(id string, entMeta *EnterpriseMeta) {
|
||||||
|
|
||||||
sid.EnterpriseMeta = *entMeta
|
sid.EnterpriseMeta = *entMeta
|
||||||
sid.EnterpriseMeta.Normalize()
|
sid.EnterpriseMeta.Normalize()
|
||||||
|
return sid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sid *ServiceID) Matches(other *ServiceID) bool {
|
func (sid *ServiceID) Matches(other *ServiceID) bool {
|
||||||
|
|
|
@ -178,11 +178,9 @@ func summarizeServices(dump structs.CheckServiceNodes) []*ServiceSummary {
|
||||||
return serv
|
return serv
|
||||||
}
|
}
|
||||||
|
|
||||||
var sid structs.ServiceID
|
|
||||||
for _, csn := range dump {
|
for _, csn := range dump {
|
||||||
svc := csn.Service
|
svc := csn.Service
|
||||||
sid.Init(svc.Service, &svc.EnterpriseMeta)
|
sum := getService(structs.NewServiceID(svc.Service, &svc.EnterpriseMeta))
|
||||||
sum := getService(sid)
|
|
||||||
sum.Nodes = append(sum.Nodes, csn.Node.Node)
|
sum.Nodes = append(sum.Nodes, csn.Node.Node)
|
||||||
sum.Kind = svc.Kind
|
sum.Kind = svc.Kind
|
||||||
sum.InstanceCount += 1
|
sum.InstanceCount += 1
|
||||||
|
|
Loading…
Reference in New Issue