|
| 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 configmodels defines the data models for entities. This file defines the |
| 16 | +// models for V2 configuration format. The defined entities are: |
| 17 | +// ConfigV2 (the top-level structure), Receivers, Exporters, Processors, Pipelines. |
| 18 | +package configmodels |
| 19 | + |
| 20 | +/* |
| 21 | +Receivers, Exporters and Processors typically have common configuration settings, however |
| 22 | +sometimes specific implementations (e.g. StackDriver) will have extra configuration settings. |
| 23 | +This requires the configuration data for these entities to be polymorphic. |
| 24 | +
|
| 25 | +To satisfy these requirements we declare interfaces Receiver, Exporter, Processor, |
| 26 | +which define the behavior. We also provide helper structs ReceiverSettings, ExporterSettings, |
| 27 | +ProcessorSettings, which define the common settings and un-marshaling from config files. |
| 28 | +
|
| 29 | +Specific Receivers/Exporters/Processors are expected to at the minimum implement the |
| 30 | +corresponding interface and if they have additional settings they must also extend |
| 31 | +the corresponding common settings struct (the easiest approach is to embed the common struct). |
| 32 | +*/ |
| 33 | + |
| 34 | +// ConfigV2 defines the configuration V2 for the various elements of collector or agent. |
| 35 | +type ConfigV2 struct { |
| 36 | + Receivers Receivers |
| 37 | + Exporters Exporters |
| 38 | + Processors Processors |
| 39 | + Pipelines Pipelines |
| 40 | +} |
| 41 | + |
| 42 | +// Receiver is the configuration of a receiver. Specific receivers must implement this |
| 43 | +// interface and will typically embed ReceiverSettings struct or a struct that extends it. |
| 44 | +type Receiver interface { |
| 45 | +} |
| 46 | + |
| 47 | +// Receivers is a map of names to Receivers. |
| 48 | +type Receivers map[string]Receiver |
| 49 | + |
| 50 | +// Exporter is the configuration of an exporter. Specific exporters must implement this |
| 51 | +// interface and will typically embed ExporterSettings struct or a struct that extends it. |
| 52 | +type Exporter interface { |
| 53 | +} |
| 54 | + |
| 55 | +// Exporters is a map of names to Exporters. |
| 56 | +type Exporters map[string]Exporter |
| 57 | + |
| 58 | +// Processor is the configuration of a processor. Specific processors must implement this |
| 59 | +// interface and will typically embed ProcessorSettings struct or a struct that extends it. |
| 60 | +type Processor interface { |
| 61 | +} |
| 62 | + |
| 63 | +// Processors is a map of names to Processors. |
| 64 | +type Processors map[string]Processor |
| 65 | + |
| 66 | +// DataType is the data type that is supported for collection. We currently support |
| 67 | +// collecting metrics and traces, this can expand in the future (e.g. logs, events, etc). |
| 68 | +type DataType int |
| 69 | + |
| 70 | +// Currently supported data types. Add new data types here when new types are supported in the future. |
| 71 | +const ( |
| 72 | + _ DataType = iota // skip 0, start types from 1. |
| 73 | + |
| 74 | + // TracesDataType is the data type tag for traces. |
| 75 | + TracesDataType |
| 76 | + |
| 77 | + // MetricsDataType is the data type tag for metrics. |
| 78 | + MetricsDataType |
| 79 | +) |
| 80 | + |
| 81 | +// Pipeline defines a single pipeline. |
| 82 | +type Pipeline struct { |
| 83 | + Name string `mapstructure:"-"` |
| 84 | + InputType DataType `mapstructure:"-"` |
| 85 | + Receivers []string `mapstructure:"receivers"` |
| 86 | + Processors []string `mapstructure:"processors"` |
| 87 | + Exporters []string `mapstructure:"exporters"` |
| 88 | +} |
| 89 | + |
| 90 | +// Pipelines is a map of names to Pipelines. |
| 91 | +type Pipelines map[string]*Pipeline |
| 92 | + |
| 93 | +// Below are common setting structs for Receivers, Exporters and Processors. |
| 94 | +// These are helper structs which you can embed when implementing your specific |
| 95 | +// receiver/exporter/processor config storage. |
| 96 | + |
| 97 | +// ReceiverSettings defines common settings for a single-protocol receiver configuration. |
| 98 | +// Specific receivers can embed this struct and extend it with more fields if needed. |
| 99 | +type ReceiverSettings struct { |
| 100 | + Enabled bool `mapstructure:"enabled"` |
| 101 | + Endpoint string `mapstructure:"endpoint"` |
| 102 | +} |
| 103 | + |
| 104 | +// ExporterSettings defines common settings for an exporter configuration. |
| 105 | +// Specific exporters can embed this struct and extend it with more fields if needed. |
| 106 | +type ExporterSettings struct { |
| 107 | + Enabled bool `mapstructure:"enabled"` |
| 108 | +} |
| 109 | + |
| 110 | +// ProcessorSettings defines common settings for a processor configuration. |
| 111 | +// Specific processors can embed this struct and extend it with more fields if needed. |
| 112 | +type ProcessorSettings struct { |
| 113 | + Enabled bool `mapstructure:"enabled"` |
| 114 | +} |
0 commit comments