-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix Shutdown behavior for batchprocessor #2537
Merged
tigrannajaryan
merged 1 commit into
open-telemetry:main
from
tigrannajaryan:feature/tigran/shutdown-test
Mar 2, 2021
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright The OpenTelemetry 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 componenttest | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/configerror" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/internal/testdata" | ||
) | ||
|
||
func verifyTraceProcessorDoesntProduceAfterShutdown(t *testing.T, factory component.ProcessorFactory, cfg configmodels.Processor) { | ||
// Create a processor and output its produce to a sink. | ||
nextSink := new(consumertest.TracesSink) | ||
processor, err := factory.CreateTracesProcessor( | ||
context.Background(), | ||
component.ProcessorCreateParams{Logger: zap.NewNop()}, | ||
cfg, | ||
nextSink, | ||
) | ||
if err != nil { | ||
if err == configerror.ErrDataTypeIsNotSupported { | ||
return | ||
} | ||
require.NoError(t, err) | ||
} | ||
err = processor.Start(context.Background(), NewNopHost()) | ||
assert.NoError(t, err) | ||
|
||
// Send some traces to the processor. | ||
const generatedCount = 10 | ||
for i := 0; i < generatedCount; i++ { | ||
processor.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneSpan()) | ||
} | ||
|
||
// Now shutdown the processor. | ||
err = processor.Shutdown(context.Background()) | ||
assert.NoError(t, err) | ||
|
||
// The Shutdown() is done. It means the processor must have sent everything we | ||
// gave it to the next sink. | ||
assert.EqualValues(t, generatedCount, nextSink.SpansCount()) | ||
} | ||
|
||
func VerifyProcessorShutdown(t *testing.T, factory component.ProcessorFactory, cfg configmodels.Processor) { | ||
verifyTraceProcessorDoesntProduceAfterShutdown(t, factory, cfg) | ||
// TODO: add metrics and logs verification. | ||
// TODO: add other shutdown verifications. | ||
} |
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
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.
I know that it sounds strange to have unittest for testing helpers but for this logic is probably good :) Maybe in a separate PR?
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.
There is a TODO to handle other data type later in the file. We can address as part of that TODO (this code may change as a result of that, so I don't want to spend time on it now).