diff --git a/api/raml/system-agent.raml b/api/raml/system-agent.raml index a2677b9b01..3a5803ad4e 100644 --- a/api/raml/system-agent.raml +++ b/api/raml/system-agent.raml @@ -51,7 +51,7 @@ schemas: body: application/json: schema: config - example: '{"Service":"edgex-support-notifications","Config":{"Clients":{"Logging":{"Host":"localhost","Port":48061,"Protocol":"http"}},"Databases":{"Primary":{"Host":"localhost","Name":"notifications","Password":"","Port":27017,"Timeout":5000,"Type":"mongodb","Username":""}},"Logging":{"EnableRemote":false,"File":"./logs/edgex-support-notifications.log"},"Registry":{"Host":"localhost","Port":8500,"Type":"consul"},"ResendLimit":2,"Service":{"BootTimeout":30000,"CheckInterval":"10s","ClientMonitor":15000,"Host":"localhost","Port":48060,"Protocol":"http","MaxResultCount":1000,"StartupMsg":"This is the Support Notifications Microservice","Timeout":5000},"Smtp":{"Host":"smtp.gmail.com","Password":"mypassword","Port":587,"Sender":"jdoe@gmail.com","Subject":"EdgeX Notification"}}}' + example: '{"Service":"edgex-support-notifications","Config":{"Clients":{"Logging":{"Host":"localhost","Port":48061,"Protocol":"http"}},"Databases":{"Primary":{"Host":"localhost","Name":"notifications","Password":"","Port":27017,"Timeout":5000,"Type":"mongodb","Username":""}},"Logging":{"EnableRemote":false,"File":"./logs/edgex-support-notifications.log"},"Registry":{"Host":"localhost","Port":8500,"Type":"consul"},"ResendLimit":2,"Service":{"BootTimeout":30000,"CheckInterval":"10s","Host":"localhost","Port":48060,"Protocol":"http","MaxResultCount":1000,"StartupMsg":"This is the Support Notifications Microservice","Timeout":5000},"Smtp":{"Host":"smtp.gmail.com","Password":"mypassword","Port":587,"Sender":"jdoe@gmail.com","Subject":"EdgeX Notification"}}}' "500": description: for unknown or unanticipated issues. /v1/metrics/{services}: diff --git a/cmd/core-command/res/configuration.toml b/cmd/core-command/res/configuration.toml index e23100654a..cbf089b7fb 100644 --- a/cmd/core-command/res/configuration.toml +++ b/cmd/core-command/res/configuration.toml @@ -3,7 +3,6 @@ LogLevel = 'INFO' [Service] BootTimeout = 30000 -ClientMonitor = 15000 CheckInterval = '10s' Host = 'localhost' Port = 48082 diff --git a/cmd/core-data/res/configuration.toml b/cmd/core-data/res/configuration.toml index bf6af5fb47..5527df5416 100644 --- a/cmd/core-data/res/configuration.toml +++ b/cmd/core-data/res/configuration.toml @@ -9,7 +9,6 @@ ChecksumAlgo = 'xxHash' [Service] BootTimeout = 30000 -ClientMonitor = 15000 CheckInterval = '10s' Host = 'localhost' Port = 48080 diff --git a/cmd/core-metadata/res/configuration.toml b/cmd/core-metadata/res/configuration.toml index b30f8097f8..9ac8c91b25 100644 --- a/cmd/core-metadata/res/configuration.toml +++ b/cmd/core-metadata/res/configuration.toml @@ -4,7 +4,6 @@ EnableValueDescriptorManagement = false [Service] BootTimeout = 30000 -ClientMonitor = 15000 CheckInterval = '10s' Host = 'localhost' Port = 48081 diff --git a/cmd/support-logging/res/configuration.toml b/cmd/support-logging/res/configuration.toml index 8ba7962e01..6b9161b164 100644 --- a/cmd/support-logging/res/configuration.toml +++ b/cmd/support-logging/res/configuration.toml @@ -4,7 +4,6 @@ LogLevel = 'INFO' [Service] BootTimeout = 30000 -ClientMonitor = 15000 CheckInterval = '10s' Host = 'localhost' Port = 48061 diff --git a/cmd/support-notifications/res/configuration.toml b/cmd/support-notifications/res/configuration.toml index 3cc2e70035..f7e92cd04b 100644 --- a/cmd/support-notifications/res/configuration.toml +++ b/cmd/support-notifications/res/configuration.toml @@ -4,7 +4,6 @@ LogLevel = 'INFO' [Service] BootTimeout = 30000 -ClientMonitor = 15000 CheckInterval = '10s' Host = 'localhost' Port = 48060 diff --git a/cmd/support-scheduler/res/configuration.toml b/cmd/support-scheduler/res/configuration.toml index 33b58ee4f9..2d434d99b4 100644 --- a/cmd/support-scheduler/res/configuration.toml +++ b/cmd/support-scheduler/res/configuration.toml @@ -4,7 +4,6 @@ LogLevel = 'INFO' [Service] BootTimeout = 30000 -ClientMonitor = 15000 CheckInterval = '10s' Host = 'localhost' Port = 48085 diff --git a/cmd/sys-mgmt-agent/res/configuration.toml b/cmd/sys-mgmt-agent/res/configuration.toml index 4978e507c4..ee42b9a6e1 100644 --- a/cmd/sys-mgmt-agent/res/configuration.toml +++ b/cmd/sys-mgmt-agent/res/configuration.toml @@ -17,7 +17,6 @@ LogLevel = 'INFO' [Service] BootTimeout = 30000 -ClientMonitor = 15000 CheckInterval = '10s' Host = 'localhost' Port = 48090 diff --git a/internal/constants.go b/internal/constants.go index 40dcf6a728..3319b04348 100644 --- a/internal/constants.go +++ b/internal/constants.go @@ -17,7 +17,6 @@ const ( BootTimeoutDefault = BootTimeoutSecondsDefault * 1000 BootTimeoutSecondsDefault = 30 BootRetrySecondsDefault = 1 - ClientMonitorDefault = 15000 ConfigFileName = "configuration.toml" ConfigStemCore = "edgex/core/" ConfigStemSecurity = "edgex/security/" diff --git a/internal/core/command/init.go b/internal/core/command/init.go index dce5b1d85b..961f11b273 100644 --- a/internal/core/command/init.go +++ b/internal/core/command/init.go @@ -19,15 +19,16 @@ import ( "context" "sync" - "github.com/edgexfoundry/edgex-go/internal/core/command/container" - errorContainer "github.com/edgexfoundry/edgex-go/internal/pkg/container" - "github.com/edgexfoundry/edgex-go/internal/pkg/errorconcept" - "github.com/edgexfoundry/edgex-go/internal/pkg/urlclient" + "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/local" bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/container" "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/startup" "github.com/edgexfoundry/go-mod-bootstrap/di" + "github.com/edgexfoundry/edgex-go/internal/core/command/container" + errorContainer "github.com/edgexfoundry/edgex-go/internal/pkg/container" + "github.com/edgexfoundry/edgex-go/internal/pkg/errorconcept" + "github.com/edgexfoundry/go-mod-core-contracts/clients" "github.com/edgexfoundry/go-mod-core-contracts/clients/metadata" "github.com/gorilla/mux" @@ -56,24 +57,13 @@ func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ // than the configured client time out would still be present. // Until that problem is addressed by larger architectural changes, if you are experiencing a bug similar to // https://github.com/edgexfoundry/edgex-go/issues/2421, the correct fix is to bump up the client timeout. - registryClient := bootstrapContainer.RegistryFrom(dic.Get) configuration := container.ConfigurationFrom(dic.Get) lc := bootstrapContainer.LoggingClientFrom(dic.Get) // initialize clients required by the service dic.Update(di.ServiceConstructorMap{ container.MetadataDeviceClientName: func(get di.Get) interface{} { - return metadata.NewDeviceClient( - urlclient.New( - ctx, - wg, - registryClient, - clients.CoreMetaDataServiceKey, - clients.ApiDeviceRoute, - configuration.Service.ClientMonitor, - configuration.Clients["Metadata"].Url()+clients.ApiDeviceRoute, - ), - ) + return metadata.NewDeviceClient(local.New(configuration.Clients["Metadata"].Url() + clients.ApiDeviceRoute)) }, errorContainer.ErrorHandlerName: func(get di.Get) interface{} { return errorconcept.NewErrorHandler(lc) diff --git a/internal/core/data/init.go b/internal/core/data/init.go index d59235e178..22be6f129e 100644 --- a/internal/core/data/init.go +++ b/internal/core/data/init.go @@ -19,15 +19,16 @@ import ( "fmt" "sync" - dataContainer "github.com/edgexfoundry/edgex-go/internal/core/data/container" - errorContainer "github.com/edgexfoundry/edgex-go/internal/pkg/container" - "github.com/edgexfoundry/edgex-go/internal/pkg/errorconcept" - "github.com/edgexfoundry/edgex-go/internal/pkg/urlclient" + "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/local" "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/container" "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/startup" "github.com/edgexfoundry/go-mod-bootstrap/di" + dataContainer "github.com/edgexfoundry/edgex-go/internal/core/data/container" + errorContainer "github.com/edgexfoundry/edgex-go/internal/pkg/container" + "github.com/edgexfoundry/edgex-go/internal/pkg/errorconcept" + "github.com/edgexfoundry/go-mod-core-contracts/clients" "github.com/edgexfoundry/go-mod-core-contracts/clients/metadata" "github.com/edgexfoundry/go-mod-messaging/messaging" @@ -53,31 +54,10 @@ func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ loadRestRoutes(b.router, dic) configuration := dataContainer.ConfigurationFrom(dic.Get) - registryClient := container.RegistryFrom(dic.Get) lc := container.LoggingClientFrom(dic.Get) - mdc := metadata.NewDeviceClient( - urlclient.New( - ctx, - wg, - registryClient, - clients.CoreMetaDataServiceKey, - clients.ApiDeviceRoute, - configuration.Service.ClientMonitor, - configuration.Clients["Metadata"].Url()+clients.ApiDeviceRoute, - ), - ) - msc := metadata.NewDeviceServiceClient( - urlclient.New( - ctx, - wg, - registryClient, - clients.CoreMetaDataServiceKey, - clients.ApiDeviceServiceRoute, - configuration.Service.ClientMonitor, - configuration.Clients["Metadata"].Url()+clients.ApiDeviceRoute, - ), - ) + mdc := metadata.NewDeviceClient(local.New(configuration.Clients["Metadata"].Url() + clients.ApiDeviceRoute)) + msc := metadata.NewDeviceServiceClient(local.New(configuration.Clients["Metadata"].Url() + clients.ApiDeviceRoute)) // Create the messaging client msgClient, err := messaging.NewMessageClient( diff --git a/internal/core/metadata/init.go b/internal/core/metadata/init.go index a306a35d1b..23dca1f715 100644 --- a/internal/core/metadata/init.go +++ b/internal/core/metadata/init.go @@ -18,10 +18,7 @@ import ( "context" "sync" - "github.com/edgexfoundry/edgex-go/internal/core/metadata/container" - errorContainer "github.com/edgexfoundry/edgex-go/internal/pkg/container" - "github.com/edgexfoundry/edgex-go/internal/pkg/errorconcept" - "github.com/edgexfoundry/edgex-go/internal/pkg/urlclient" + "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/local" bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/container" "github.com/edgexfoundry/go-mod-bootstrap/bootstrap/startup" @@ -30,6 +27,10 @@ import ( "github.com/edgexfoundry/go-mod-core-contracts/clients/coredata" "github.com/edgexfoundry/go-mod-core-contracts/clients/notifications" "github.com/gorilla/mux" + + "github.com/edgexfoundry/edgex-go/internal/core/metadata/container" + errorContainer "github.com/edgexfoundry/edgex-go/internal/pkg/container" + "github.com/edgexfoundry/edgex-go/internal/pkg/errorconcept" ) // Bootstrap contains references to dependencies required by the BootstrapHandler. @@ -56,7 +57,6 @@ func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ // Until that problem is addressed by larger architectural changes, if you are experiencing a bug similar to // https://github.com/edgexfoundry/edgex-go/issues/2421, the correct fix is to bump up the client timeout. configuration := container.ConfigurationFrom(dic.Get) - registryClient := bootstrapContainer.RegistryFrom(dic.Get) // add dependencies to container dic.Update(di.ServiceConstructorMap{ @@ -65,29 +65,12 @@ func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ }, container.CoreDataValueDescriptorClientName: func(get di.Get) interface{} { return coredata.NewValueDescriptorClient( - urlclient.New( - ctx, - wg, - registryClient, - clients.CoreDataServiceKey, - clients.ApiValueDescriptorRoute, - configuration.Service.ClientMonitor, - configuration.Clients["CoreData"].Url()+clients.ApiValueDescriptorRoute, - ), - ) + local.New(configuration.Clients["CoreData"].Url() + clients.ApiValueDescriptorRoute)) }, container.NotificationsClientName: func(get di.Get) interface{} { return notifications.NewNotificationsClient( - urlclient.New( - ctx, - wg, - registryClient, - clients.SupportNotificationsServiceKey, - clients.ApiNotificationRoute, - configuration.Service.ClientMonitor, - configuration.Clients["Notifications"].Url()+clients.ApiNotificationRoute, - ), - ) + local.New(configuration.Clients["Notifications"].Url() + clients.ApiNotificationRoute)) + }, }) diff --git a/internal/pkg/endpoint/endpoint.go b/internal/pkg/endpoint/endpoint.go deleted file mode 100644 index 4b408dee2e..0000000000 --- a/internal/pkg/endpoint/endpoint.go +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright 2018 Dell Inc. - * Copyright (c) 2019 Intel Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - *******************************************************************************/ - -package endpoint - -import ( - "context" - "fmt" - "sync" - "time" - - "github.com/edgexfoundry/go-mod-core-contracts/clients/interfaces" - "github.com/edgexfoundry/go-mod-registry/registry" -) - -type Endpoint struct { - ctx context.Context - wg *sync.WaitGroup - registryClient registry.Client - serviceKey string // The key of the service as found in the service registry (e.g. Consul) - path string // The path to the service's endpoint following port number in the URL - interval int // The interval in milliseconds governing how often the client polls to keep the endpoint current - -} - -func New( - ctx context.Context, - wg *sync.WaitGroup, - registryClient registry.Client, - serviceKey string, - path string, - interval int) *Endpoint { - - return &Endpoint{ - ctx: ctx, - wg: wg, - registryClient: registryClient, - serviceKey: serviceKey, - path: path, - interval: interval, - } -} - -func (e Endpoint) Monitor() chan interfaces.URLStream { - ch := make(chan interfaces.URLStream) - ticker := time.NewTicker(time.Millisecond * time.Duration(e.interval)) - e.wg.Add(1) - go func() { - defer e.wg.Done() - - // run fetchURL once before looping so we get the first check before the first timer interval - e.fetchURL(ch) - for { - select { - case <-e.ctx.Done(): - ticker.Stop() - return - - case <-ticker.C: - e.fetchURL(ch) - } - } - }() - - return ch -} - -func (e Endpoint) fetchURL(ch chan interfaces.URLStream) { - endpoint, err := (e.registryClient).GetServiceEndpoint(e.serviceKey) - if err != nil { - _, _ = fmt.Println(fmt.Errorf("unable to get service endpoint for %s: %s", e.serviceKey, err.Error())) - return - } - - ch <- interfaces.URLStream(fmt.Sprintf("http://%s:%v%s", endpoint.Host, endpoint.Port, e.path)) -} diff --git a/internal/pkg/urlclient/factory.go b/internal/pkg/urlclient/factory.go deleted file mode 100644 index a2a245f54b..0000000000 --- a/internal/pkg/urlclient/factory.go +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright 2020 Dell Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - *******************************************************************************/ - -// urlclient provides functions to integrate the client code in go-mod-core-contracts with application specific code -package urlclient - -import ( - "context" - "sync" - - "github.com/edgexfoundry/go-mod-core-contracts/clients/interfaces" - "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/local" - "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/retry" - "github.com/edgexfoundry/go-mod-registry/registry" - - "github.com/edgexfoundry/edgex-go/internal/pkg/endpoint" -) - -// New is a factory function that uses parameters defined in edgex-go to decide which implementation of URLClient to use -func New( - ctx context.Context, - wg *sync.WaitGroup, - registryClient registry.Client, - serviceKey string, - route string, - interval int, - url string) interfaces.URLClient { - - if registryClient != nil { - return retry.New( - endpoint.New( - ctx, - wg, - registryClient, - serviceKey, - route, - interval, - ).Monitor(), - interval, // retry interval == interval because we don't need to check for an update before an update - interval*10, // this scalar multiplier was chosen because it seemed reasonable - ) - } - - return local.New(url) -} diff --git a/internal/system/agent/clients/general_test.go b/internal/system/agent/clients/general_test.go index e4ba96c436..245ae16c3a 100644 --- a/internal/system/agent/clients/general_test.go +++ b/internal/system/agent/clients/general_test.go @@ -17,7 +17,7 @@ package clients import ( "testing" - "github.com/edgexfoundry/edgex-go/internal/pkg/urlclient" + "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/local" "github.com/edgexfoundry/go-mod-core-contracts/clients/general" "github.com/stretchr/testify/assert" @@ -36,7 +36,7 @@ func TestGetForKnownReturnsExpectedValues(t *testing.T) { const clientName = "clientName" sut := NewGeneral() - client := general.NewGeneralClient(urlclient.New(nil, nil, nil, "", "", 0, "/")) + client := general.NewGeneralClient(local.New("/")) sut.Set(clientName, client) result, ok := sut.Get(clientName) diff --git a/internal/system/agent/direct/metrics.go b/internal/system/agent/direct/metrics.go index b0cb01961d..2e452de28b 100644 --- a/internal/system/agent/direct/metrics.go +++ b/internal/system/agent/direct/metrics.go @@ -19,11 +19,10 @@ import ( "context" "encoding/json" "fmt" - "sync" - "github.com/edgexfoundry/edgex-go/internal" + "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/local" + "github.com/edgexfoundry/edgex-go/internal/pkg/telemetry" - "github.com/edgexfoundry/edgex-go/internal/pkg/urlclient" "github.com/edgexfoundry/edgex-go/internal/system" agentClients "github.com/edgexfoundry/edgex-go/internal/system/agent/clients" "github.com/edgexfoundry/edgex-go/internal/system/agent/concurrent" @@ -107,17 +106,7 @@ func (m *metrics) metricsViaDirectService(ctx context.Context, serviceName strin } // Add the serviceName key to the map where the value is the respective GeneralClient - client = general.NewGeneralClient( - urlclient.New( - ctx, - &sync.WaitGroup{}, - m.registryClient, - e.ServiceId, - "/", - internal.ClientMonitorDefault, - configClient.Url()+clients.ApiMetricsRoute, - ), - ) + client = general.NewGeneralClient(local.New(configClient.Url() + clients.ApiMetricsRoute)) m.genClients.Set(e.ServiceId, client) } diff --git a/internal/system/agent/getconfig/executor.go b/internal/system/agent/getconfig/executor.go index f91c69e3a0..0d220b71fe 100644 --- a/internal/system/agent/getconfig/executor.go +++ b/internal/system/agent/getconfig/executor.go @@ -17,10 +17,9 @@ package getconfig import ( "context" "fmt" - "sync" - "github.com/edgexfoundry/edgex-go/internal" - "github.com/edgexfoundry/edgex-go/internal/pkg/urlclient" + "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/local" + agentClients "github.com/edgexfoundry/edgex-go/internal/system/agent/clients" bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/config" @@ -87,17 +86,7 @@ func (e executor) Do(ctx context.Context, serviceName string) (string, error) { } // Add the serviceName key to the map where the value is the respective GeneralClient - client = general.NewGeneralClient( - urlclient.New( - ctx, - &sync.WaitGroup{}, - e.registryClient, - ep.ServiceId, - "/", - internal.ClientMonitorDefault, - configClient.Url()+clients.ApiConfigRoute, - ), - ) + client = general.NewGeneralClient(local.New(configClient.Url() + clients.ApiConfigRoute)) e.genClients.Set(ep.ServiceId, client) } diff --git a/internal/system/agent/init.go b/internal/system/agent/init.go index d32b6997b1..abdce6c131 100644 --- a/internal/system/agent/init.go +++ b/internal/system/agent/init.go @@ -18,8 +18,8 @@ import ( "context" "sync" - "github.com/edgexfoundry/edgex-go/internal" - "github.com/edgexfoundry/edgex-go/internal/pkg/urlclient" + "github.com/edgexfoundry/go-mod-core-contracts/clients/urlclient/local" + "github.com/edgexfoundry/edgex-go/internal/system/agent/clients" "github.com/edgexfoundry/edgex-go/internal/system/agent/container" "github.com/edgexfoundry/edgex-go/internal/system/agent/direct" @@ -107,22 +107,11 @@ func (b *Bootstrap) BootstrapHandler(ctx context.Context, _ *sync.WaitGroup, _ s }) generalClients := container.GeneralClientsFrom(dic.Get) - registryClient := bootstrapContainer.RegistryFrom(dic.Get) for serviceKey, serviceName := range b.listDefaultServices() { generalClients.Set( serviceKey, - general.NewGeneralClient( - urlclient.New( - ctx, - &sync.WaitGroup{}, - registryClient, - serviceKey, - "/", - internal.ClientMonitorDefault, - configuration.Clients[serviceName].Url(), - ), - ), + general.NewGeneralClient(local.New(configuration.Clients[serviceName].Url())), ) }