-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor component and factory interface definitions
As we are preparing for Beta release we want to cleanup publicly exported types and interfaces and do all necessary refactoring and breaking changes now, before the Beta release. We will have a lot less leeway for breaking changes after the Beta release. Component related type declarations are now all in the `component` package. This makes it possible for the interfaces to reference each other. This was were very restricted earlier because component interfaces were in 5 different packages and many proposals were impossible to implement because they would result in circular dependencies between packages. (An example upcoming new capability that is enabled by this refactoring is for components to query the Host for other components and for factories). List of changes in this commit: - Move all factory interfaces and component interfaces to component package. - Rename old factories and components interfaces to use V1 suffix for clarity. - Eliminate forced checks that components implement factories. This is already enforced by the compiler when the factory is added to the Defaults() and was unnecessary code. - Eliminated some unnecessary codes (removed overall over 200 lines). - Run `go mod tidy` on testbed. Warning: this is a breaking change to publicly exported types and function signatures. We announced that a breaking change is comming. Once we agree to merge this commit we will need to announce the exact list of changes and guide component authors to modify their components accordingly. Further proposed future changes: - Once all components are migrated to V2 internal representation, delete all V1 definitions and get rid of V2 suffix. This will likely be done while we are still in Beta phase, before the Stable release.
- Loading branch information
Tigran Najaryan
committed
Mar 23, 2020
1 parent
0912b29
commit b7a73e4
Showing
96 changed files
with
651 additions
and
865 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
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,73 @@ | ||
// Copyright 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 "fmt" | ||
|
||
// MakeReceiverFactoryMap takes a list of receiver factories and returns a map | ||
// with factory type as keys. It returns a non-nil error when more than one factories | ||
// have the same type. | ||
func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[string]ReceiverFactory, error) { | ||
fMap := map[string]ReceiverFactory{} | ||
for _, f := range factories { | ||
if _, ok := fMap[f.Type()]; ok { | ||
return fMap, fmt.Errorf("duplicate receiver factory %q", f.Type()) | ||
} | ||
fMap[f.Type()] = f | ||
} | ||
return fMap, nil | ||
} | ||
|
||
// MakeProcessorFactoryMap takes a list of processor factories and returns a map | ||
// with factory type as keys. It returns a non-nil error when more than one factories | ||
// have the same type. | ||
func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[string]ProcessorFactory, error) { | ||
fMap := map[string]ProcessorFactory{} | ||
for _, f := range factories { | ||
if _, ok := fMap[f.Type()]; ok { | ||
return fMap, fmt.Errorf("duplicate processor factory %q", f.Type()) | ||
} | ||
fMap[f.Type()] = f | ||
} | ||
return fMap, nil | ||
} | ||
|
||
// MakeExporterFactoryMap takes a list of exporter factories and returns a map | ||
// with factory type as keys. It returns a non-nil error when more than one factories | ||
// have the same type. | ||
func MakeExporterFactoryMap(factories ...ExporterFactory) (map[string]ExporterFactory, error) { | ||
fMap := map[string]ExporterFactory{} | ||
for _, f := range factories { | ||
if _, ok := fMap[f.Type()]; ok { | ||
return fMap, fmt.Errorf("duplicate exporter factory %q", f.Type()) | ||
} | ||
fMap[f.Type()] = f | ||
} | ||
return fMap, nil | ||
} | ||
|
||
// MakeExtensionFactoryMap takes a list of extension factories and returns a map | ||
// with factory type as keys. It returns a non-nil error when more than one factories | ||
// have the same type. | ||
func MakeExtensionFactoryMap(factories ...ExtensionFactory) (map[string]ExtensionFactory, error) { | ||
fMap := map[string]ExtensionFactory{} | ||
for _, f := range factories { | ||
if _, ok := fMap[f.Type()]; ok { | ||
return fMap, fmt.Errorf("duplicate extension factory %q", f.Type()) | ||
} | ||
fMap[f.Type()] = f | ||
} | ||
return fMap, nil | ||
} |
Oops, something went wrong.