Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPSRAMPOTLP exporter with masking #2

Merged
merged 5 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions exporter/opsrampotlpexporter/cfg-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
type: '*opsrampotlpexporter.Config'
fields:
- name: timeout
type: time.Duration
kind: int64
default: 5s
doc: |
Timeout is the timeout for every attempt to send data to the backend.
- name: sending_queue
type: exporterhelper.QueueSettings
kind: struct
fields:
- name: enabled
kind: bool
default: true
doc: |
Enabled indicates whether to not enqueue batches before sending to the consumerSender.
- name: num_consumers
kind: int
default: 10
doc: |
NumConsumers is the number of consumers from the queue.
- name: queue_size
kind: int
default: 5000
doc: |
QueueSize is the maximum number of batches allowed in queue at a given time.
- name: retry_on_failure
type: exporterhelper.RetrySettings
kind: struct
fields:
- name: enabled
kind: bool
default: true
doc: |
Enabled indicates whether to not retry sending batches in case of export failure.
- name: initial_interval
type: time.Duration
kind: int64
default: 5s
doc: |
InitialInterval the time to wait after the first failure before retrying.
- name: max_interval
type: time.Duration
kind: int64
default: 30s
doc: |
MaxInterval is the upper bound on backoff interval. Once this value is reached the delay between
consecutive retries will always be `MaxInterval`.
- name: max_elapsed_time
type: time.Duration
kind: int64
default: 5m0s
doc: |
MaxElapsedTime is the maximum amount of time (including retries) spent trying to send a request/batch.
Once this value is reached, the data is discarded.
- name: endpoint
kind: string
doc: |
The target to which the exporter is going to send traces or metrics,
using the gRPC protocol. The valid syntax is described at
https://github.com/grpc/grpc/blob/master/doc/naming.md.
- name: compression
kind: string
doc: |
The compression key for supported compression types within
collector. Supports `gzip`, `snappy` and `zstd`.
- name: ca_file
kind: string
doc: |
Path to the CA cert. For a client this verifies the server certificate.
For a server this verifies client certificates. If empty uses system root CA.
(optional)
- name: cert_file
kind: string
doc: |
Path to the TLS cert to use for TLS required connections. (optional)
- name: key_file
kind: string
doc: |
Path to the TLS key to use for TLS required connections. (optional)
- name: insecure
kind: bool
doc: |
In gRPC when set to true, this is used to disable the client transport security.
See https://godoc.org/google.golang.org/grpc#WithInsecure.
In HTTP, this disables verifying the server's certificate chain and host name
(InsecureSkipVerify in the tls Config). Please refer to
https://godoc.org/crypto/tls#Config for more information.
(optional, default false)
- name: server_name_override
kind: string
doc: |
ServerName requested by client for virtual hosting.
This sets the ServerName in the TLSConfig. Please refer to
https://godoc.org/crypto/tls#Config for more information. (optional)
- name: keepalive
type: '*configgrpc.KeepaliveClientConfig'
kind: ptr
doc: |
The keepalive parameters for gRPC client. See grpc.WithKeepaliveParams
(https://godoc.org/google.golang.org/grpc#WithKeepaliveParams).
fields:
- name: time
type: time.Duration
kind: int64
- name: timeout
type: time.Duration
kind: int64
- name: permit_without_stream
kind: bool
- name: read_buffer_size
kind: int
doc: |
ReadBufferSize for gRPC client. See grpc.WithReadBufferSize
(https://godoc.org/google.golang.org/grpc#WithReadBufferSize).
- name: write_buffer_size
kind: int
default: 524288
doc: |
WriteBufferSize for gRPC gRPC. See grpc.WithWriteBufferSize
(https://godoc.org/google.golang.org/grpc#WithWriteBufferSize).
- name: wait_for_ready
kind: bool
doc: |
WaitForReady parameter configures client to wait for ready state before sending data.
(https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md)
- name: headers
type: map[string]string
kind: map
doc: |
The headers associated with gRPC requests.
- name: per_rpc_auth
type: '*configgrpc.PerRPCAuthConfig'
kind: ptr
doc: |
PerRPCAuth parameter configures the client to send authentication data on a per-RPC basis.
fields:
- name: type
kind: string
doc: |
AuthType represents the authentication type to use. Currently, only 'bearer' is supported.
- name: bearer_token
kind: string
doc: |
BearerToken specifies the bearer token to use for every RPC.
- name: balancer_name
kind: string
doc: |
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
87 changes: 87 additions & 0 deletions exporter/opsrampotlpexporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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 opsrampotlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexporter"

import (
"errors"
"fmt"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

const grantType = "client_credentials"

type MaskingSettings struct {
Regexp string `mapstructure:"regexp"`
Placeholder string `mapstructure:"placeholder"`
}

type SecuritySettings struct {
OAuthServiceURL string `mapstructure:"oauth_service_url"`
ClientId string `mapstructure:"client_id"`
ClientSecret string `mapstructure:"client_secret"`
}

type Credentials struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn string `json:"expired_in"`
Scope string `json:"scope"`
}

func (s *SecuritySettings) Validate() error {
if len(s.OAuthServiceURL) == 0 {
return errors.New("oauth service url missed")
}

if len(s.ClientId) == 0 {
return errors.New("client_id missed")
}

if len(s.ClientSecret) == 0 {
return errors.New("client_secret missed")
}

return nil
}

// Config defines configuration for OpenCensus exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`

Security SecuritySettings `mapstructure:"security"`
configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
Masking []MaskingSettings `mapstructure:"masking"`
}

var _ config.Exporter = (*Config)(nil)

// Validate checks if the exporter configuration is valid
func (cfg *Config) Validate() error {
if err := cfg.QueueSettings.Validate(); err != nil {
return fmt.Errorf("queue settings has invalid configuration: %w", err)
}

if err := cfg.Security.Validate(); err != nil {
return fmt.Errorf("security settings has invalid configuration: %w", err)
}

return nil
}
95 changes: 95 additions & 0 deletions exporter/opsrampotlpexporter/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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 opsrampotlpexporter

import (
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/service/servicetest"
)

func TestLoadConfig(t *testing.T) {
factories, err := componenttest.NopFactories()
assert.NoError(t, err)

factory := NewFactory()
factories.Exporters[typeStr] = factory

cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories)

require.NoError(t, err)
require.NotNil(t, cfg)

e := cfg.Exporters[config.NewComponentID(typeStr)]

//e1 := cfg.Exporters[config.NewComponentIDWithName(typeStr, "2")]
assert.Equal(t, e,
&Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "")),
TimeoutSettings: exporterhelper.TimeoutSettings{
Timeout: 10 * time.Second,
},
RetrySettings: exporterhelper.RetrySettings{
Enabled: true,
InitialInterval: 10 * time.Second,
MaxInterval: 1 * time.Minute,
MaxElapsedTime: 10 * time.Minute,
},
QueueSettings: exporterhelper.QueueSettings{
Enabled: true,
NumConsumers: 2,
QueueSize: 10,
},
Security: SecuritySettings{
ClientId: "id",
ClientSecret: "secret",
OAuthServiceURL: "url",
},
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: map[string]string{
"can you have a . here?": "F0000000-0000-0000-0000-000000000000",
"header1": "234",
"another": "somevalue",
},
Endpoint: "1.2.3.4:1234",
Compression: "gzip",
TLSSetting: configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
CAFile: "/var/lib/mycert.pem",
},
Insecure: false,
},
Keepalive: &configgrpc.KeepaliveClientConfig{
Time: 20 * time.Second,
PermitWithoutStream: true,
Timeout: 30 * time.Second,
},
WriteBufferSize: 512 * 1024,
BalancerName: "round_robin",
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("nop")},
},
})
}
16 changes: 16 additions & 0 deletions exporter/opsrampotlpexporter/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 otlpexporter exports data by using the OTLP format to a gPRC endpoint.
package opsrampotlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexporter"
Loading