-
Notifications
You must be signed in to change notification settings - Fork 98
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
Bug 1954640: Support of gatherers with different periods #399
Merged
openshift-merge-robot
merged 5 commits into
openshift:master
from
Serhii1011010:support-of-gatherers-with-different-periods
May 11, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
312 changes: 177 additions & 135 deletions
312
docs/insights-archive-sample/insights-operator/gathers.json
Large diffs are not rendered by default.
Oops, something went wrong.
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,13 @@ | ||
package config | ||
|
||
// MockConfigurator returns the config from conf field | ||
type MockConfigurator struct { | ||
Conf *Controller | ||
} | ||
|
||
func (mc *MockConfigurator) Config() *Controller { | ||
return mc.Conf | ||
} | ||
func (mc *MockConfigurator) ConfigChanged() (<-chan struct{}, func()) { | ||
return nil, nil | ||
} |
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
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,76 @@ | ||
package periodic | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/openshift/insights-operator/pkg/config" | ||
"github.com/openshift/insights-operator/pkg/gather" | ||
"github.com/openshift/insights-operator/pkg/gatherers" | ||
"github.com/openshift/insights-operator/pkg/recorder" | ||
) | ||
|
||
func Test_Controller_CustomPeriodGatherer(t *testing.T) { | ||
c, mockRecorder := getMocksForPeriodicTest([]gatherers.Interface{ | ||
&gather.MockGatherer{CanFail: true}, | ||
&gather.MockCustomPeriodGatherer{Period: 999 * time.Hour}, | ||
}) | ||
|
||
c.Gather() | ||
// 6 gatherers + metadata | ||
assert.Len(t, mockRecorder.Records, 7) | ||
mockRecorder.Reset() | ||
|
||
c.Gather() | ||
// 5 gatherers + metadata (one is low priority and we need to wait 999 hours to get it | ||
assert.Len(t, mockRecorder.Records, 6) | ||
mockRecorder.Reset() | ||
} | ||
|
||
func Test_Controller_CustomPeriodGathererNoPeriod(t *testing.T) { | ||
mockGatherer := gather.MockCustomPeriodGathererNoPeriod{ShouldBeProcessed: true} | ||
c, mockRecorder := getMocksForPeriodicTest([]gatherers.Interface{ | ||
&gather.MockGatherer{CanFail: true}, | ||
&mockGatherer, | ||
}) | ||
|
||
c.Gather() | ||
// 6 gatherers + metadata | ||
assert.Len(t, mockRecorder.Records, 7) | ||
assert.Equal(t, 1, mockGatherer.ShouldBeProcessedNowWasCalledNTimes) | ||
assert.Equal(t, 1, mockGatherer.UpdateLastProcessingTimeWasCalledNTimes) | ||
mockRecorder.Reset() | ||
|
||
mockGatherer.ShouldBeProcessed = false | ||
|
||
c.Gather() | ||
// 5 gatherers + metadata (we've just disabled one gatherer) | ||
assert.Len(t, mockRecorder.Records, 6) | ||
assert.Equal(t, 2, mockGatherer.ShouldBeProcessedNowWasCalledNTimes) | ||
// ShouldBeProcessedNow had returned false so we didn't call UpdateLastProcessingTime | ||
assert.Equal(t, 1, mockGatherer.UpdateLastProcessingTimeWasCalledNTimes) | ||
mockRecorder.Reset() | ||
|
||
mockGatherer.ShouldBeProcessed = true | ||
|
||
c.Gather() | ||
assert.Len(t, mockRecorder.Records, 7) | ||
assert.Equal(t, 3, mockGatherer.ShouldBeProcessedNowWasCalledNTimes) | ||
assert.Equal(t, 2, mockGatherer.UpdateLastProcessingTimeWasCalledNTimes) | ||
mockRecorder.Reset() | ||
} | ||
|
||
// TODO: cover more things | ||
|
||
func getMocksForPeriodicTest(gatherers []gatherers.Interface) (*Controller, *recorder.MockRecorder) { | ||
mockConfigurator := config.MockConfigurator{Conf: &config.Controller{ | ||
Report: true, | ||
Interval: time.Hour, | ||
Gather: []string{gather.AllGatherersConst}, | ||
}} | ||
mockRecorder := recorder.MockRecorder{} | ||
|
||
return New(&mockConfigurator, &mockRecorder, gatherers, nil), &mockRecorder | ||
} |
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.
Lol... so I was experimenting with setting some short timeout here (e.g 10s) and the log kinda exploded....especially due to two following gatherers:
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.
I was experimenting with this again and maybe I would remove the extra logging statement in https://github.com/openshift/insights-operator/pull/399/files#diff-bdd45c95687562d23e5fdd43dea644d8fb86c95354192cedd72835743ba9fc0fR104. WDYT? I think the error should be obvious from a particular gatherer function and we shouldn't log it again....
I noticed it's almost the same now in https://github.com/openshift/insights-operator/blob/master/pkg/gather/clusterconfig/0_gatherer.go#L216, but the verbosity level is 5.
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.
But where else do we log it?
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.
The particular gatherer should log its own error IMO and it should also be visible in the metadata.
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.
But if we forget to log the error in the gatherer we're only gonna get it in the metadata
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.
Yes, what I am trying to say is that it should be gatherer responsibility (i.e. we shouldn't forget). The metadata is most important for me, because we usually don't have the IO log in our archive.
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.
Well, from my point of view it's better to do it once in the calling code than many times in gatherers. But I agree that metadata is more important than logs for us.