-
Notifications
You must be signed in to change notification settings - Fork 29
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
Platforms connection in health-check #325
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
4139ea3
Async health check
DimitarPetrov 144ea91
Tests adaptation
DimitarPetrov 61157b4
Make health configurable externally
DimitarPetrov 9f62a81
Install health later
DimitarPetrov 81ff665
Export ConvertStatus function
DimitarPetrov 115e2a4
Fix health settings validation
DimitarPetrov 37f9bc4
Attach logger to health
DimitarPetrov 4f21ed9
Address PR comments
DimitarPetrov 421d88f
Configuration per indicator and refactoring
DimitarPetrov 30ab52e
Add health status listener
DimitarPetrov d25a87d
Minor tweaks
DimitarPetrov 794c3b0
Fix indicator interval type
DimitarPetrov 40fb02b
Fix tests
DimitarPetrov 37c03dd
Remove unused import
DimitarPetrov f138807
Extract indicator configuration and address PR comments
DimitarPetrov ce4d4bb
Add error to panic
DimitarPetrov 3a34381
Address PR comments
DimitarPetrov 91eb2a9
minor fix
DimitarPetrov 31f86b7
Add active status to platform
DimitarPetrov 0ac6fb5
Platforms connection in health
DimitarPetrov 17a1bf7
Merge branch 'master' into platform-health
DimitarPetrov 7ffd051
Add tests
DimitarPetrov 9621fb0
Fix formatting
DimitarPetrov 743afcf
Merge branch 'master' into platform-health
DimitarPetrov a2ba4fe
Hide platform details on unauthorized healthcheck
DimitarPetrov 89ab1ff
Rename migrations
DimitarPetrov b04b750
Fix test last migration
DimitarPetrov dfe900f
Add default value to migration
DimitarPetrov 3e864fd
Last Active default value
DimitarPetrov 46bc9c5
Initial fix health configuration
DimitarPetrov aace011
fix failing tests
KirilKabakchiev c9db83e
Address PR comments
DimitarPetrov 11fb13f
Refactor platform indicator
DimitarPetrov bf23318
Strip indicator error on unauthorized request
DimitarPetrov cfd8a90
Fix formatting
DimitarPetrov d2fd944
Fix squash tag handling
DimitarPetrov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2018 The Service Manager Authors | ||
* | ||
* 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 healthcheck | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Peripli/service-manager/pkg/health" | ||
"github.com/Peripli/service-manager/pkg/types" | ||
"github.com/Peripli/service-manager/storage" | ||
) | ||
|
||
// NewPlatformIndicator returns new health indicator for platforms of given type | ||
func NewPlatformIndicator(ctx context.Context, repository storage.Repository, fatal func(*types.Platform) bool) health.Indicator { | ||
if fatal == nil { | ||
fatal = func(platform *types.Platform) bool { | ||
return true | ||
} | ||
} | ||
return &platformIndicator{ | ||
ctx: ctx, | ||
repository: repository, | ||
fatal: fatal, | ||
} | ||
} | ||
|
||
type platformIndicator struct { | ||
repository storage.Repository | ||
ctx context.Context | ||
fatal func(*types.Platform) bool | ||
} | ||
|
||
// Name returns the name of the indicator | ||
func (pi *platformIndicator) Name() string { | ||
return health.PlatformsIndicatorName | ||
} | ||
|
||
// Status returns status of the health check | ||
func (pi *platformIndicator) Status() (interface{}, error) { | ||
objList, err := pi.repository.List(pi.ctx, types.PlatformType) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not fetch platforms health from storage: %v", err) | ||
} | ||
platforms := objList.(*types.Platforms).Platforms | ||
|
||
details := make(map[string]*health.Health) | ||
inactivePlatforms := 0 | ||
fatalInactivePlatforms := 0 | ||
for _, platform := range platforms { | ||
if platform.Active { | ||
details[platform.Name] = health.New().WithStatus(health.StatusUp). | ||
WithDetail("type", platform.Type) | ||
} else { | ||
details[platform.Name] = health.New().WithStatus(health.StatusDown). | ||
WithDetail("since", platform.LastActive). | ||
WithDetail("type", platform.Type) | ||
inactivePlatforms++ | ||
if pi.fatal(platform) { | ||
fatalInactivePlatforms++ | ||
} | ||
} | ||
} | ||
|
||
if fatalInactivePlatforms > 0 { | ||
err = fmt.Errorf("there are %d inactive platforms %d of them are fatal", inactivePlatforms, fatalInactivePlatforms) | ||
} | ||
|
||
return details, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2018 The Service Manager Authors | ||
* | ||
* 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 healthcheck | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/Peripli/service-manager/pkg/health" | ||
"github.com/Peripli/service-manager/pkg/types" | ||
storagefakes2 "github.com/Peripli/service-manager/storage/storagefakes" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"time" | ||
) | ||
|
||
var _ = Describe("Platforms Indicator", func() { | ||
var indicator health.Indicator | ||
var repository *storagefakes2.FakeStorage | ||
var ctx context.Context | ||
var platform *types.Platform | ||
|
||
BeforeEach(func() { | ||
ctx = context.TODO() | ||
repository = &storagefakes2.FakeStorage{} | ||
platform = &types.Platform{ | ||
Name: "test-platform", | ||
Type: "kubernetes", | ||
Active: false, | ||
LastActive: time.Now(), | ||
} | ||
indicator = NewPlatformIndicator(ctx, repository, nil) | ||
}) | ||
|
||
Context("Name", func() { | ||
It("should not be empty", func() { | ||
Expect(indicator.Name()).Should(Equal(health.PlatformsIndicatorName)) | ||
}) | ||
}) | ||
|
||
Context("There are inactive platforms", func() { | ||
BeforeEach(func() { | ||
objectList := &types.Platforms{[]*types.Platform{platform}} | ||
repository.ListReturns(objectList, nil) | ||
}) | ||
It("should return error", func() { | ||
details, err := indicator.Status() | ||
health := details.(map[string]*health.Health)[platform.Name] | ||
Expect(err).Should(HaveOccurred()) | ||
Expect(health.Details["since"]).ShouldNot(BeNil()) | ||
}) | ||
}) | ||
|
||
Context("Storage returns error", func() { | ||
var expectedErr error | ||
BeforeEach(func() { | ||
expectedErr = errors.New("storage err") | ||
repository.ListReturns(nil, expectedErr) | ||
}) | ||
It("should return error", func() { | ||
_, err := indicator.Status() | ||
Expect(err).Should(HaveOccurred()) | ||
Expect(err.Error()).To(ContainSubstring(expectedErr.Error())) | ||
}) | ||
}) | ||
|
||
Context("All platforms are active", func() { | ||
BeforeEach(func() { | ||
platform.Active = true | ||
objectList := &types.Platforms{[]*types.Platform{platform}} | ||
repository.ListReturns(objectList, nil) | ||
}) | ||
It("should not return error", func() { | ||
_, err := indicator.Status() | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remap the status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to adopt library’s status “ok” and “failed” this change should be propagated everywhere since all the components check UP to determine if it is started correctly.