Skip to content

Commit

Permalink
Merge branch 'open-telemetry:main' into ottl_string_interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsafyan authored Oct 14, 2024
2 parents 2aeeca5 + d20c3f8 commit 903bec9
Show file tree
Hide file tree
Showing 53 changed files with 599 additions and 218 deletions.
27 changes: 27 additions & 0 deletions .chloggen/aggregate_labels_empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: metricstransform

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The previously removed functionality of aggregating against an empty label set is restored.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [34430]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
27 changes: 27 additions & 0 deletions .chloggen/codeboten_validate-telemetrygen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: telemetrygen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: ensure validate is called

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35745]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
27 changes: 27 additions & 0 deletions .chloggen/lkwronski.issue-29441-slice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/ottl

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow indexing string slice type

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [29441]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
27 changes: 27 additions & 0 deletions .chloggen/stanza-windows-remote-session-leak.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: stanza/input/windows

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Close remote session while resubscribing

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35577]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
27 changes: 27 additions & 0 deletions .chloggen/telemetrygen-insecureskipverify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: telemetrygen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Enable the `--otlp-insecure-skip-verify` flag

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35735]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
2 changes: 1 addition & 1 deletion cmd/githubgen/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ m1rp
jriguera
abhishek-at-cloudwerx
joker-star-l
ArthurSens
michael-burt
2 changes: 1 addition & 1 deletion cmd/telemetrygen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
go.opentelemetry.io/otel/sdk/log v0.6.0
go.opentelemetry.io/otel/sdk/metric v1.30.0
go.opentelemetry.io/otel/trace v1.30.0
go.opentelemetry.io/proto/otlp v1.3.1
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
golang.org/x/time v0.7.0
Expand All @@ -45,7 +46,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
Expand Down
58 changes: 21 additions & 37 deletions cmd/telemetrygen/internal/common/tls_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,37 @@ func caPool(caFile string) (*x509.CertPool, error) {
return pool, nil
}

func GetTLSCredentialsForGRPCExporter(caFile string, cAuth ClientAuth) (credentials.TransportCredentials, error) {

pool, err := caPool(caFile)
func GetTLSCredentialsForGRPCExporter(
caFile string,
cAuth ClientAuth,
insecureSkipVerify bool,
) (credentials.TransportCredentials, error) {
tlsConfig, err := getTLSConfig(caFile, cAuth, insecureSkipVerify)
if err != nil {
return nil, err
}
return credentials.NewTLS(tlsConfig), nil
}

var creds credentials.TransportCredentials

if caFile != "" {
creds = credentials.NewTLS(&tls.Config{
RootCAs: pool,
})
} else {
creds = credentials.NewTLS(&tls.Config{})
}

// Configuration for mTLS
if cAuth.Enabled {
keypair, err := tls.LoadX509KeyPair(cAuth.ClientCertFile, cAuth.ClientKeyFile)
if err != nil {
return nil, err
}
creds = credentials.NewTLS(&tls.Config{
RootCAs: pool,
Certificates: []tls.Certificate{keypair},
})
}

return creds, nil
func GetTLSCredentialsForHTTPExporter(
caFile string,
cAuth ClientAuth,
insecureSkipVerify bool,
) (*tls.Config, error) {
return getTLSConfig(caFile, cAuth, insecureSkipVerify)
}

func GetTLSCredentialsForHTTPExporter(caFile string, cAuth ClientAuth) (*tls.Config, error) {
pool, err := caPool(caFile)
if err != nil {
return nil, err
func getTLSConfig(caFile string, cAuth ClientAuth, insecureSkipVerify bool) (*tls.Config, error) {
tlsCfg := tls.Config{
InsecureSkipVerify: insecureSkipVerify,
}

var tlsCfg tls.Config

if caFile != "" {
tlsCfg = tls.Config{
RootCAs: pool,
pool, err := caPool(caFile)
if err != nil {
return nil, err
}
} else {
tlsCfg = tls.Config{}
tlsCfg.RootCAs = pool
}

// Configuration for mTLS
Expand All @@ -82,7 +67,6 @@ func GetTLSCredentialsForHTTPExporter(caFile string, cAuth ClientAuth) (*tls.Con
if err != nil {
return nil, err
}
tlsCfg.ClientAuth = tls.RequireAndVerifyClientCert
tlsCfg.Certificates = []tls.Certificate{keypair}
}
return &tlsCfg, nil
Expand Down
6 changes: 6 additions & 0 deletions cmd/telemetrygen/internal/logs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package logs

import (
"fmt"

"github.com/spf13/pflag"

"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/common"
Expand Down Expand Up @@ -36,6 +38,10 @@ func (c *Config) Flags(fs *pflag.FlagSet) {

// Validate validates the test scenario parameters.
func (c *Config) Validate() error {
if c.TotalDuration <= 0 && c.NumLogs <= 0 {
return fmt.Errorf("either `logs` or `duration` must be greater than 0")
}

if c.TraceID != "" {
if err := common.ValidateTraceID(c.TraceID); err != nil {
return err
Expand Down
8 changes: 6 additions & 2 deletions cmd/telemetrygen/internal/logs/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func grpcExporterOptions(cfg *Config) ([]otlploggrpc.Option, error) {
if cfg.Insecure {
grpcExpOpt = append(grpcExpOpt, otlploggrpc.WithInsecure())
} else {
credentials, err := common.GetTLSCredentialsForGRPCExporter(cfg.CaFile, cfg.ClientAuth)
credentials, err := common.GetTLSCredentialsForGRPCExporter(
cfg.CaFile, cfg.ClientAuth, cfg.InsecureSkipVerify,
)
if err != nil {
return nil, fmt.Errorf("failed to get TLS credentials: %w", err)
}
Expand All @@ -47,7 +49,9 @@ func httpExporterOptions(cfg *Config) ([]otlploghttp.Option, error) {
if cfg.Insecure {
httpExpOpt = append(httpExpOpt, otlploghttp.WithInsecure())
} else {
tlsCfg, err := common.GetTLSCredentialsForHTTPExporter(cfg.CaFile, cfg.ClientAuth)
tlsCfg, err := common.GetTLSCredentialsForHTTPExporter(
cfg.CaFile, cfg.ClientAuth, cfg.InsecureSkipVerify,
)
if err != nil {
return nil, fmt.Errorf("failed to get TLS credentials: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/telemetrygen/internal/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func Start(cfg *Config) error {
}

if err = Run(cfg, expFunc, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
return err
}

Expand All @@ -69,10 +68,12 @@ func Start(cfg *Config) error {

// Run executes the test scenario.
func Run(c *Config, exp func() (sdklog.Exporter, error), logger *zap.Logger) error {
if err := c.Validate(); err != nil {
return err
}

if c.TotalDuration > 0 {
c.NumLogs = 0
} else if c.NumLogs <= 0 {
return fmt.Errorf("either `logs` or `duration` must be greater than 0")
}

limit := rate.Limit(c.Rate)
Expand Down
52 changes: 52 additions & 0 deletions cmd/telemetrygen/internal/logs/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,58 @@ func TestLogsWithTraceIDAndSpanID(t *testing.T) {
}
}

func TestValidate(t *testing.T) {
tests := []struct {
name string
cfg *Config
wantErrMessage string
}{
{
name: "No duration or NumLogs",
cfg: &Config{
Config: common.Config{
WorkerCount: 1,
},
TraceID: "123",
},
wantErrMessage: "either `logs` or `duration` must be greater than 0",
},
{
name: "TraceID invalid",
cfg: &Config{
Config: common.Config{
WorkerCount: 1,
},
NumLogs: 5,
TraceID: "123",
},
wantErrMessage: "TraceID must be a 32 character hex string, like: 'ae87dadd90e9935a4bc9660628efd569'",
},
{
name: "SpanID invalid",
cfg: &Config{
Config: common.Config{
WorkerCount: 1,
},
NumLogs: 5,
TraceID: "ae87dadd90e9935a4bc9660628efd569",
SpanID: "123",
},
wantErrMessage: "SpanID must be a 16 character hex string, like: '5828fa4960140870'",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &mockExporter{}
expFunc := func() (sdklog.Exporter, error) {
return m, nil
}
logger, _ := zap.NewDevelopment()
require.EqualError(t, Run(tt.cfg, expFunc, logger), tt.wantErrMessage)
})
}
}

func configWithNoAttributes(qty int, body string) *Config {
return &Config{
Body: body,
Expand Down
6 changes: 6 additions & 0 deletions cmd/telemetrygen/internal/metrics/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package metrics

import (
"fmt"

"github.com/spf13/pflag"

"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/common"
Expand Down Expand Up @@ -39,6 +41,10 @@ func (c *Config) Flags(fs *pflag.FlagSet) {

// Validate validates the test scenario parameters.
func (c *Config) Validate() error {
if c.TotalDuration <= 0 && c.NumMetrics <= 0 {
return fmt.Errorf("either `metrics` or `duration` must be greater than 0")
}

if c.TraceID != "" {
if err := common.ValidateTraceID(c.TraceID); err != nil {
return err
Expand Down
Loading

0 comments on commit 903bec9

Please sign in to comment.