forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make component interfaces uniform (open-telemetry#488)
This change fixes inconsistencies in component interfaces. Motivation: - Uniformness results in reduction of code that currently has to deal with differences. - Processor.Start is missing and is important for allowing processors to communicate with the Host. What's changed: - Introduced Component interface. - Unified Host interface. - Added a Start function to processors (via Component interface). - Start/Shutdown is now called for Processors from service start/shutdown. - Receivers, Exporters, Processors, Extensions now embed Component interface. - Replaced StartTraceReception/StartMetricsReception by single Start function for receivers. - Replaced StopTraceReception/StopMetricsReception by single Shutdown function for receivers. Note: before merging this we need to announce the change in Gitter since it breaks existing implementations in contrib (although the fix is easy). Resolves open-telemetry#477 Resolves open-telemetry#262
- Loading branch information
1 parent
da64a78
commit ba03d67
Showing
54 changed files
with
499 additions
and
332 deletions.
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,43 @@ | ||
// Copyright 2019 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 component | ||
|
||
import "context" | ||
|
||
// Component is either a receiver, exporter, processor or extension. | ||
type Component interface { | ||
// Start tells the component to start. Host parameter can be used for communicating | ||
// with the host after Start() has already returned. If error is returned by | ||
// Start() then the collector startup will be aborted. | ||
// If this is an exporter component it may prepare for exporting | ||
// by connecting to the endpoint. | ||
Start(host Host) error | ||
|
||
// Shutdown is invoked during service shutdown. | ||
Shutdown() error | ||
} | ||
|
||
// Host represents the entity that is hosting a Component. It is used to allow communication | ||
// between the Component and its host (normally the service.Application is the host). | ||
type Host interface { | ||
// ReportFatalError is used to report to the host that the extension | ||
// encountered a fatal error (i.e.: an error that the instance can't recover | ||
// from) after its start function had already returned. | ||
ReportFatalError(err error) | ||
|
||
// Context returns a context provided by the host to be used on the component | ||
// operations. | ||
Context() context.Context | ||
} |
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,15 @@ | ||
// Copyright 2019 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 component |
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,62 @@ | ||
// Copyright 2019 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 config | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/component" | ||
"github.com/open-telemetry/opentelemetry-collector/consumer/consumerdata" | ||
) | ||
|
||
func TestExampleExporterConsumer(t *testing.T) { | ||
exp := &ExampleExporterConsumer{} | ||
host := component.NewMockHost() | ||
assert.Equal(t, false, exp.ExporterStarted) | ||
err := exp.Start(host) | ||
assert.NoError(t, err) | ||
assert.Equal(t, true, exp.ExporterStarted) | ||
|
||
assert.Equal(t, 0, len(exp.Traces)) | ||
err = exp.ConsumeTraceData(context.Background(), consumerdata.TraceData{}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(exp.Traces)) | ||
|
||
assert.Equal(t, 0, len(exp.Metrics)) | ||
err = exp.ConsumeMetricsData(context.Background(), consumerdata.MetricsData{}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(exp.Metrics)) | ||
|
||
assert.Equal(t, false, exp.ExporterShutdown) | ||
err = exp.Shutdown() | ||
assert.NoError(t, err) | ||
assert.Equal(t, true, exp.ExporterShutdown) | ||
} | ||
|
||
func TestExampleReceiverProducer(t *testing.T) { | ||
rcv := &ExampleReceiverProducer{} | ||
host := component.NewMockHost() | ||
assert.Equal(t, false, rcv.Started) | ||
err := rcv.Start(host) | ||
assert.NoError(t, err) | ||
assert.Equal(t, true, rcv.Started) | ||
|
||
err = rcv.Shutdown() | ||
assert.NoError(t, err) | ||
assert.Equal(t, true, rcv.Started) | ||
} |
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
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
Oops, something went wrong.