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: add better error handlings when common config is missing #566

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
5 changes: 5 additions & 0 deletions bootstrap/handlers/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func (cb *ClientsBootstrap) BootstrapHandler(
return false
}

if len(config.GetBootstrap().Service.RequestTimeout) == 0 {
lc.Error("Service.RequestTimeout found empty in service's configuration, missing common config? Use -cp or -cc flags for common config")
return false
}

// TODO: Move following outside loop when multiple messaging based clients exist
timeout, err := time.ParseDuration(config.GetBootstrap().Service.RequestTimeout)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions bootstrap/handlers/httpserver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*******************************************************************************
* Copyright 2019 Dell Inc.
* Copyright 2021-2022 IOTech Ltd
* Copyright 2023 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
Expand Down Expand Up @@ -86,6 +87,12 @@ func (b *HttpServer) BootstrapHandler(

bootstrapConfig := container.ConfigurationFrom(dic.Get).GetBootstrap()

if bootstrapConfig.Service.Port == 0 {
// should not be 0 as if it were set in local config
lc.Error("Service.Port is missing from service's configuration or should not be 0 in local private config")
return false
}

// this allows env override to explicitly set the value used
// for ListenAndServe as needed for different deployments
port := strconv.Itoa(bootstrapConfig.Service.Port)
Expand All @@ -96,6 +103,11 @@ func (b *HttpServer) BootstrapHandler(
addr = bootstrapConfig.Service.Host + ":" + port
}

if len(bootstrapConfig.Service.RequestTimeout) == 0 {
lc.Error("Service.RequestTimeout found empty in service's configuration, missing common config? Use -cp or -cc flags for common config")
return false
}

timeout, err := time.ParseDuration(bootstrapConfig.Service.RequestTimeout)
if err != nil {
lc.Errorf("unable to parse RequestTimeout value of %s to a duration: %v", bootstrapConfig.Service.RequestTimeout, err)
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/handlers/messaging.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2022 Intel Corp.
* Copyright 2022-2023 Intel Corp.
*
* 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
Expand Down Expand Up @@ -41,8 +41,8 @@ func MessagingBootstrapHandler(ctx context.Context, wg *sync.WaitGroup, startupT
return true
}

if len(messageBus.Host) == 0 {
lc.Error("MessageBus configuration not set or missing from service's GetBootstrap() implementation")
if len(messageBus.Host) == 0 || messageBus.Port == 0 || len(messageBus.Protocol) == 0 || len(messageBus.Type) == 0 {
lc.Error("MessageBus configuration is incomplete, missing common config? Use -cp or -cc flags for common config.")
return false
}

Expand Down
6 changes: 5 additions & 1 deletion bootstrap/registration/registry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright 2019 Dell Inc.
* Copyright 2020 Intel Inc.
* Copyright 2020, 2023 Intel 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
Expand Down Expand Up @@ -68,6 +68,10 @@ func createRegistryClient(
}
}

if len(bootstrapConfig.Registry.Host) == 0 || bootstrapConfig.Registry.Port == 0 || len(bootstrapConfig.Registry.Type) == 0 {
return nil, errors.New("Registry configuration is empty or incomplete, missing common config? Use -cp or -cc flags for common config.")
}

registryConfig := registryTypes.Config{
Host: bootstrapConfig.Registry.Host,
Port: bootstrapConfig.Registry.Port,
Expand Down