Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 6d4c33d

Browse files
author
Steven Karis
authored
Add Unified factory interfaces (#428)
This changes adds three factory interfaces, one for each type of generic component that can be added. `*DataExporterFactory ` creates a new `*DataExporter` which is a thin extension of `*DataProcessor`. By inheriting this interface, we can use an Exporter as a *DataProcessor, while still getting strong-typing guarantees when evaluating whether or not a pipeline is valid (it should end in an exporter). `*DataProcessorFactory` creates a new `*DataProcessor` which can be used as an intermediate step in the processing workflow. `*ReceiverFactory` creates a new `*Receiver` which listens for traffic and passes along data it receives to the next `*DataProcessor`
1 parent baec3ed commit 6d4c33d

3 files changed

Lines changed: 156 additions & 0 deletions

File tree

exporter/factory.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package exporter
16+
17+
import (
18+
"github.com/spf13/viper"
19+
20+
"github.com/census-instrumentation/opencensus-service/processor"
21+
)
22+
23+
// TraceDataExporter composes TraceDataProcessor with some additional
24+
// exporter-specific functions. This helps the service core to identify which
25+
// TraceDataProcessors are Exporters and which are internal processing
26+
// components, so that better validation of pipelines can be done.
27+
type TraceDataExporter interface {
28+
processor.TraceDataProcessor
29+
30+
// ExportFormat gets the name of the format in which this exporter sends its data.
31+
ExportFormat() string
32+
}
33+
34+
// TraceDataExporterFactory is an interface that builds a new TraceDataExporter based on
35+
// some viper.Viper configuration.
36+
type TraceDataExporterFactory interface {
37+
// Type gets the type of the TraceDataExporter created by this factory.
38+
Type() string
39+
// NewFromViper takes a viper.Viper config and creates a new TraceDataExporter.
40+
NewFromViper(cfg *viper.Viper) (TraceDataExporter, error)
41+
// DefaultConfig returns the default configuration for TraceDataExporter
42+
// created by this factory.
43+
DefaultConfig() *viper.Viper
44+
}
45+
46+
// MetricsDataExporter composes MetricsDataProcessor with some additional
47+
// exporter-specific functions. This helps the service core to identify which
48+
// MetricsDataProcessors are Exporters and which are internal processing
49+
// components, so that better validation of pipelines can be done.
50+
type MetricsDataExporter interface {
51+
processor.MetricsDataProcessor
52+
53+
// ExportFormat gets the name of the format in which this exporter sends its data.
54+
ExportFormat() string
55+
}
56+
57+
// MetricsDataExporterFactory is an interface that builds a new MetricsDataExporter based on
58+
// some viper.Viper configuration.
59+
type MetricsDataExporterFactory interface {
60+
// Type gets the type of the MetricsDataExporter created by this factory.
61+
Type() string
62+
// NewFromViper takes a viper.Viper config and creates a new MetricsDataExporter.
63+
NewFromViper(cfg *viper.Viper) (MetricsDataExporter, error)
64+
// DefaultConfig returns the default configuration for MetricsDataExporter
65+
// created by this factory.
66+
DefaultConfig() *viper.Viper
67+
}

processor/factory.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package processor
16+
17+
import "github.com/spf13/viper"
18+
19+
// TraceDataProcessorFactory is an interface that builds a new TraceDataProcessor based on
20+
// some viper.Viper configuration.
21+
type TraceDataProcessorFactory interface {
22+
// Type gets the type of the TraceDataProcessor created by this factory.
23+
Type() string
24+
// NewFromViper takes a viper.Viper config and creates a new TraceDataProcessor which uses next as
25+
// the next TraceDataProcessor in the pipeline.
26+
NewFromViper(cfg *viper.Viper, next TraceDataProcessor) (TraceDataProcessor, error)
27+
// DefaultConfig returns the default configuration for TraceDataProcessors
28+
// created by this factory.
29+
DefaultConfig() *viper.Viper
30+
}
31+
32+
// MetricsDataProcessorFactory is an interface that builds a new MetricsDataProcessor based on
33+
// some viper.Viper configuration.
34+
type MetricsDataProcessorFactory interface {
35+
// Type gets the type of the MetricsDataProcessor created by this factory.
36+
Type() string
37+
// NewFromViper takes a viper.Viper config and creates a new MetricsDataProcessor which uses next as
38+
// the next MetricsDataProcessor in the pipeline.
39+
NewFromViper(cfg *viper.Viper, next MetricsDataProcessor) (MetricsDataProcessor, error)
40+
// DefaultConfig returns the default configuration for MetricsDataProcessors
41+
// created by this factory.
42+
DefaultConfig() *viper.Viper
43+
}

receiver/factory.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package receiver
16+
17+
import (
18+
"github.com/census-instrumentation/opencensus-service/processor"
19+
"github.com/spf13/viper"
20+
)
21+
22+
// TraceReceiverFactory is an interface that builds a new TraceReceiver based on
23+
// some viper.Viper configuration.
24+
type TraceReceiverFactory interface {
25+
// Type gets the type of the TraceReceiver created by this factory.
26+
Type() string
27+
// NewFromViper takes a viper.Viper config and creates a new TraceReceiver which uses next as the
28+
// next TraceDataProcessor in the pipeline.
29+
NewFromViper(cfg *viper.Viper, next processor.TraceDataProcessor) (TraceReceiver, error)
30+
// DefaultConfig returns the default configuration for TraceReceivers
31+
// created by this factory.
32+
DefaultConfig() *viper.Viper
33+
}
34+
35+
// MetricsReceiverFactory is an interface that builds a new MetricsReceiver based on
36+
// some viper.Viper configuration.
37+
type MetricsReceiverFactory interface {
38+
// Type gets the type of the MetricsReceiver created by this factory.
39+
Type() string
40+
// NewFromViper takes a viper.Viper config and creates a new MetricsReceiver which uses next as the
41+
// next MetricsDataProcessor in the pipeline.
42+
NewFromViper(cfg *viper.Viper, next processor.MetricsDataProcessor) (MetricsReceiver, error)
43+
// DefaultConfig returns the default configuration for MetricsReceivers
44+
// created by this factory.
45+
DefaultConfig() *viper.Viper
46+
}

0 commit comments

Comments
 (0)