Skip to content

Commit

Permalink
Merge branch 'main' into configtestnew
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdandrutu committed May 26, 2021
2 parents 253246d + df76aa3 commit ce0c98d
Show file tree
Hide file tree
Showing 83 changed files with 1,269 additions and 780 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Remove unused logstest package (#3222)
- Introduce `AppSettings` instead of `Parameters` (#3163)
- Rename `configtest.LoadConfigFile` to `configtest.LoadConfigAndValidate` (#3306)
- Remove unused testutil.TempSocketName (#3291)
- Move BigEndian helper functions in `tracetranslator` to an internal package.(#3298)

## 💡 Enhancements 💡
Expand Down
35 changes: 11 additions & 24 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package config defines the data models for entities. This file defines the
// models for configuration format. The defined entities are:
// Config (the top-level structure), Receivers, Exporters, Processors, Pipelines.
//
// Receivers, Exporters and Processors typically have common configuration settings, however
// sometimes specific implementations will have extra configuration settings.
// This requires the configuration data for these entities to be polymorphic.
//
// To satisfy these requirements we declare interfaces Receiver, Exporter, Processor,
// which define the behavior. We also provide helper structs ReceiverSettings, ExporterSettings,
// ProcessorSettings, which define the common settings and un-marshaling from config files.
//
// Specific Receivers/Exporters/Processors are expected to at the minimum implement the
// corresponding interface and if they have additional settings they must also extend
// the corresponding common settings struct (the easiest approach is to embed the common struct).
package config

import (
"errors"
"fmt"

"go.opentelemetry.io/collector/config/configparser"
)

var (
Expand Down Expand Up @@ -97,7 +84,7 @@ func (cfg *Config) Validate() error {
}
}

// Check that all enabled extensions in the service are configured
// Check that all enabled extensions in the service are configured.
if err := cfg.validateServiceExtensions(); err != nil {
return err
}
Expand All @@ -110,7 +97,7 @@ func (cfg *Config) Validate() error {
func (cfg *Config) validateServiceExtensions() error {
// Validate extensions.
for _, ref := range cfg.Service.Extensions {
// Check that the name referenced in the Service extensions exists in the top-level extensions
// Check that the name referenced in the Service extensions exists in the top-level extensions.
if cfg.Extensions[ref] == nil {
return fmt.Errorf("service references extension %q which does not exist", ref)
}
Expand All @@ -134,28 +121,28 @@ func (cfg *Config) validateServicePipelines() error {

// Validate pipeline receiver name references.
for _, ref := range pipeline.Receivers {
// Check that the name referenced in the pipeline's receivers exists in the top-level receivers
// Check that the name referenced in the pipeline's receivers exists in the top-level receivers.
if cfg.Receivers[ref] == nil {
return fmt.Errorf("pipeline %q references receiver %q which does not exist", pipeline.Name, ref)
}
}

// Validate pipeline processor name references
// Validate pipeline processor name references.
for _, ref := range pipeline.Processors {
// Check that the name referenced in the pipeline's processors exists in the top-level processors.
if cfg.Processors[ref] == nil {
return fmt.Errorf("pipeline %q references processor %q which does not exist", pipeline.Name, ref)
}
}

// Validate pipeline has at least one exporter
// Validate pipeline has at least one exporter.
if len(pipeline.Exporters) == 0 {
return fmt.Errorf("pipeline %q must have at least one exporter", pipeline.Name)
}

// Validate pipeline exporter name references.
for _, ref := range pipeline.Exporters {
// Check that the name referenced in the pipeline's Exporters exists in the top-level Exporters
// Check that the name referenced in the pipeline's Exporters exists in the top-level Exporters.
if cfg.Exporters[ref] == nil {
return fmt.Errorf("pipeline %q references exporter %q which does not exist", pipeline.Name, ref)
}
Expand All @@ -166,10 +153,10 @@ func (cfg *Config) validateServicePipelines() error {

// Service defines the configurable components of the service.
type Service struct {
// Extensions is the ordered list of extensions configured for the service.
// Extensions are the ordered list of extensions configured for the service.
Extensions []ComponentID

// Pipelines is the set of data pipelines configured for the service.
// Pipelines are the set of data pipelines configured for the service.
Pipelines Pipelines
}

Expand All @@ -188,7 +175,7 @@ type CustomUnmarshable interface {
// Unmarshal is a function that un-marshals a Parser into the unmarshable struct in a custom way.
// componentSection *Parser
// The config for this specific component. May be nil or empty if no config available.
Unmarshal(componentSection *Parser) error
Unmarshal(componentSection *configparser.Parser) error
}

// DataType is the data type that is supported for collection. We currently support
Expand Down
4 changes: 2 additions & 2 deletions config/configauth/configauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ var (
errAuthenticatorNotProvided = errors.New("authenticator not provided")
)

// Authentication defines the auth settings for the receiver
// Authentication defines the auth settings for the receiver.
type Authentication struct {
// Authenticator specifies the name of the extension to use in order to authenticate the incoming data point.
AuthenticatorName string `mapstructure:"authenticator"`
}

// GetAuthenticator attempts to select the appropriate from the list of extensions, based on the requested extension name.
// GetAuthenticator attempts to select the appropriate Authenticator from the list of extensions, based on the requested extension name.
// If an authenticator is not found, an error is returned.
func GetAuthenticator(extensions map[config.ComponentID]component.Extension, requested string) (Authenticator, error) {
if requested == "" {
Expand Down
18 changes: 18 additions & 0 deletions config/configauth/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 configauth implements the configuration settings to
// ensure authentication on incoming requests, and allows
// exporters to add authentication on outgoing requests.
package configauth
6 changes: 1 addition & 5 deletions config/configcheck/configcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package configcheck has checks to be applied to configuration
// objects implemented by factories of components used in the OpenTelemetry
// collector. It is recommended for implementers of components to run the
// validations available on this package.
package configcheck

import (
Expand Down Expand Up @@ -167,7 +163,7 @@ func checkStructFieldTags(f reflect.StructField) error {

switch f.Type.Kind() {
case reflect.Struct:
// It is another struct, continue down-level
// It is another struct, continue down-level.
return validateConfigDataType(f.Type)

case reflect.Map, reflect.Slice, reflect.Array:
Expand Down
19 changes: 19 additions & 0 deletions config/configcheck/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 configcheck has checks to be applied to configuration
// objects implemented by factories of components used in the OpenTelemetry
// collector. It is recommended for implementers of components to run the
// validations available on this package.
package configcheck
25 changes: 12 additions & 13 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package configgrpc defines the gRPC configuration settings.
package configgrpc

import (
Expand All @@ -34,7 +33,7 @@ import (
"go.opentelemetry.io/collector/config/configtls"
)

// Compression gRPC keys for supported compression types within collector
// Compression gRPC keys for supported compression types within collector.
const (
CompressionUnsupported = ""
CompressionGzip = "gzip"
Expand All @@ -43,13 +42,13 @@ const (
)

var (
// Map of opentelemetry compression types to grpc registered compression types
// Map of opentelemetry compression types to grpc registered compression types.
grpcCompressionKeyMap = map[string]string{
CompressionGzip: gzip.Name,
}
)

// Allowed balancer names to be set in grpclb_policy to discover the servers
// Allowed balancer names to be set in grpclb_policy to discover the servers.
var allowedBalancerNames = []string{roundrobin.Name, grpc.PickFirstBalancerName}

// KeepaliveClientConfig exposes the keepalive.ClientParameters to be used by the exporter.
Expand All @@ -75,15 +74,15 @@ type GRPCClientSettings struct {
// TLSSetting struct exposes TLS client configuration.
TLSSetting configtls.TLSClientSetting `mapstructure:",squash"`

// The keepalive parameters for gRPC client. See grpc.WithKeepaliveParams
// The keepalive parameters for gRPC client. See grpc.WithKeepaliveParams.
// (https://godoc.org/google.golang.org/grpc#WithKeepaliveParams).
Keepalive *KeepaliveClientConfig `mapstructure:"keepalive"`

// ReadBufferSize for gRPC client. See grpc.WithReadBufferSize
// ReadBufferSize for gRPC client. See grpc.WithReadBufferSize.
// (https://godoc.org/google.golang.org/grpc#WithReadBufferSize).
ReadBufferSize int `mapstructure:"read_buffer_size"`

// WriteBufferSize for gRPC gRPC. See grpc.WithWriteBufferSize
// WriteBufferSize for gRPC gRPC. See grpc.WithWriteBufferSize.
// (https://godoc.org/google.golang.org/grpc#WithWriteBufferSize).
WriteBufferSize int `mapstructure:"write_buffer_size"`

Expand All @@ -97,7 +96,7 @@ type GRPCClientSettings struct {
// PerRPCAuth parameter configures the client to send authentication data on a per-RPC basis.
PerRPCAuth *PerRPCAuthConfig `mapstructure:"per_rpc_auth"`

// Sets the balancer in grpclb_policy to discover the servers. Default is pick_first
// Sets the balancer in grpclb_policy to discover the servers. Default is pick_first.
// https://github.com/grpc/grpc-go/blob/master/examples/features/load_balancing/README.md
BalancerName string `mapstructure:"balancer_name"`
}
Expand Down Expand Up @@ -152,11 +151,11 @@ type GRPCServerSettings struct {
// It has effect only for streaming RPCs.
MaxConcurrentStreams uint32 `mapstructure:"max_concurrent_streams"`

// ReadBufferSize for gRPC server. See grpc.ReadBufferSize
// ReadBufferSize for gRPC server. See grpc.ReadBufferSize.
// (https://godoc.org/google.golang.org/grpc#ReadBufferSize).
ReadBufferSize int `mapstructure:"read_buffer_size"`

// WriteBufferSize for gRPC server. See grpc.WriteBufferSize
// WriteBufferSize for gRPC server. See grpc.WriteBufferSize.
// (https://godoc.org/google.golang.org/grpc#WriteBufferSize).
WriteBufferSize int `mapstructure:"write_buffer_size"`

Expand All @@ -167,7 +166,7 @@ type GRPCServerSettings struct {
Auth *configauth.Authentication `mapstructure:"auth,omitempty"`
}

// ToDialOptions maps configgrpc.GRPCClientSettings to a slice of dial options for gRPC
// ToDialOptions maps configgrpc.GRPCClientSettings to a slice of dial options for gRPC.
func (gcs *GRPCClientSettings) ToDialOptions() ([]grpc.DialOption, error) {
var opts []grpc.DialOption
if gcs.Compression != "" {
Expand Down Expand Up @@ -240,7 +239,7 @@ func (gss *GRPCServerSettings) ToListener() (net.Listener, error) {
return gss.NetAddr.Listen()
}

// ToServerOption maps configgrpc.GRPCServerSettings to a slice of server options for gRPC
// ToServerOption maps configgrpc.GRPCServerSettings to a slice of server options for gRPC.
func (gss *GRPCServerSettings) ToServerOption(ext map[config.ComponentID]component.Extension) ([]grpc.ServerOption, error) {
var opts []grpc.ServerOption

Expand Down Expand Up @@ -312,7 +311,7 @@ func (gss *GRPCServerSettings) ToServerOption(ext map[config.ComponentID]compone
}

// GetGRPCCompressionKey returns the grpc registered compression key if the
// passed in compression key is supported, and CompressionUnsupported otherwise
// passed in compression key is supported, and CompressionUnsupported otherwise.
func GetGRPCCompressionKey(compressionType string) string {
compressionKey := strings.ToLower(compressionType)
if encodingKey, ok := grpcCompressionKeyMap[compressionKey]; ok {
Expand Down
15 changes: 13 additions & 2 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package configgrpc

import (
"context"
"io/ioutil"
"os"
"path"
"runtime"
"testing"
Expand All @@ -31,7 +33,6 @@ import (
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configtls"
otelcol "go.opentelemetry.io/collector/internal/data/protogen/collector/trace/v1"
"go.opentelemetry.io/collector/testutil"
)

func TestDefaultGrpcClientSettings(t *testing.T) {
Expand Down Expand Up @@ -453,7 +454,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on windows")
}
socketName := testutil.TempSocketName(t)
socketName := tempSocketName(t)
gss := &GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: socketName,
Expand Down Expand Up @@ -525,3 +526,13 @@ func TestWithPerRPCAuthInvalidAuthType(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, dialOpts)
}

// tempSocketName provides a temporary Unix socket name for testing.
func tempSocketName(t *testing.T) string {
tmpfile, err := ioutil.TempFile("", "sock")
require.NoError(t, err)
require.NoError(t, tmpfile.Close())
socket := tmpfile.Name()
require.NoError(t, os.Remove(socket))
return socket
}
17 changes: 17 additions & 0 deletions config/configgrpc/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 configgrpc defines the configuration settings to create
// a gRPC client and server.
package configgrpc
2 changes: 1 addition & 1 deletion config/configgrpc/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
package configgrpc

import (
// import the gzip package with auto-registers the gzip grpc compressor
// Import the gzip package which auto-registers the gzip gRPC compressor.
_ "google.golang.org/grpc/encoding/gzip"
)
2 changes: 1 addition & 1 deletion config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (hcs *HTTPClientSettings) ToClient() (*http.Client, error) {
}, nil
}

// Custom RoundTripper that add headers
// Custom RoundTripper that add headers.
type headerRoundTripper struct {
transport http.RoundTripper
headers map[string]string
Expand Down
17 changes: 17 additions & 0 deletions config/confighttp/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 confighttp defines the configuration settings
// for creating an HTTP client and server.
package confighttp
Loading

0 comments on commit ce0c98d

Please sign in to comment.