Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose the RequestTimeout configuration setting to app service #1039

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app-service-template/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/eclipse/paho.mqtt.golang v1.3.5 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v2 v2.1.0 // indirect
github.com/edgexfoundry/go-mod-configuration/v2 v2.1.0 // indirect
github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.6 // indirect
github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.7 // indirect
github.com/edgexfoundry/go-mod-registry/v2 v2.1.0 // indirect
github.com/edgexfoundry/go-mod-secrets/v2 v2.1.0 // indirect
github.com/fatih/color v1.9.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions app-service-template/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/edgexfoundry/go-mod-configuration/v2 v2.1.0/go.mod h1:MvHit0MxBXN4bC8
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.1.0/go.mod h1:I6UhBPCREubcU0ouIGBdZlNG5Xx4NijUVN5rvEtD03k=
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.2.0-dev.9 h1:EeXfSNWIHpG6sugmW7DjRcA/faeMS8QirRBU01B1smA=
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.2.0-dev.9/go.mod h1:FYFqOHl4OxULCnWecVcBatvk9f/BnRPwivLmARi+YCM=
github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.6 h1:u9u6eTeXT91ZZfQv0g4T1thi3uB46cMGAUpjTKgP1Yk=
github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.6/go.mod h1:+X6C0h8ZTJe+lLU2AGJfiAzCJK3zL+yM6cej9VC+79E=
github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.7 h1:O7C5NBlN03NMSPS7a6vG8ZTO1qyoiiN62HRyDw9dUNk=
github.com/edgexfoundry/go-mod-messaging/v2 v2.2.0-dev.7/go.mod h1:+X6C0h8ZTJe+lLU2AGJfiAzCJK3zL+yM6cej9VC+79E=
github.com/edgexfoundry/go-mod-registry/v2 v2.1.0 h1:ks0ejtLLUYKuoKrUBbWxygCU7q2mBFJlHE/+dEzV2Gw=
github.com/edgexfoundry/go-mod-registry/v2 v2.1.0/go.mod h1:+MNlQm8Ks9ZmxqrMK4O3KdBA6E7nRK9M+qBtv/1lPcA=
github.com/edgexfoundry/go-mod-secrets/v2 v2.1.0 h1:ASVZCZUv6cwM2GVoMJNb7rk5R7cw70S1gsut1yX8OXk=
Expand Down
15 changes: 15 additions & 0 deletions internal/app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strings"
"sync"
"syscall"
"time"

"github.com/edgexfoundry/app-functions-sdk-go/v2/internal"
"github.com/edgexfoundry/app-functions-sdk-go/v2/internal/appfunction"
Expand Down Expand Up @@ -88,6 +89,7 @@ type Service struct {
commandLine commandLineFlags
flags *flags.Default
configProcessor *config.Processor
requestTimeout time.Duration
}

type commandLineFlags struct {
Expand Down Expand Up @@ -405,6 +407,11 @@ func (svc *Service) AddFunctionsPipelineForTopics(id string, topics []string, tr
return nil
}

// RequestTimeout returns the Request Timeout duration that was parsed from the Service.RequestTimeout configuration
func (svc *Service) RequestTimeout() time.Duration {
return svc.requestTimeout
}

// ApplicationSettings returns the values specified in the custom configuration section.
func (svc *Service) ApplicationSettings() map[string]string {
return svc.config.ApplicationSettings
Expand Down Expand Up @@ -505,6 +512,14 @@ func (svc *Service) Initialize() error {
return fmt.Errorf("boostrapping failed")
}

configuration := container.ConfigurationFrom(svc.dic.Get)
var err error

svc.requestTimeout, err = time.ParseDuration(configuration.Service.RequestTimeout)
if err != nil {
return fmt.Errorf("unable to parse Service.RequestTimeout configuration as a time duration: %s", err.Error())
}

svc.runtime = runtime.NewGolangRuntime(svc.serviceKey, svc.targetType, svc.dic)

// Bootstrapping is complete, so now need to retrieve the needed objects from the containers.
Expand Down
22 changes: 19 additions & 3 deletions pkg/interfaces/mocks/ApplicationService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/interfaces/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package interfaces

import (
"net/http"
"time"

bootstrapInterfaces "github.com/edgexfoundry/go-mod-bootstrap/v2/bootstrap/interfaces"
"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/interfaces"
Expand Down Expand Up @@ -71,6 +72,8 @@ type ApplicationService interface {
// A reference to this ApplicationService is add the the context that is passed to the handler, which
// can be retrieved using the `AppService` key
AddRoute(route string, handler func(http.ResponseWriter, *http.Request), methods ...string) error
// RequestTimeout returns the configured request timeout value from [Service] section.
RequestTimeout() time.Duration
// ApplicationSettings returns the key/value map of custom settings
ApplicationSettings() map[string]string
// GetAppSetting is a convenience function return a setting from the ApplicationSetting
Expand Down