-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bump-otelgrpc-to-fix-CVE-2023-47108
- Loading branch information
Showing
14 changed files
with
669 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package otelcol | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
scraperhelper "go.opentelemetry.io/collector/receiver/scraperhelper" | ||
) | ||
|
||
var ( | ||
errNonPositiveInterval = errors.New("requires positive value") | ||
errGreaterThanZero = errors.New("requires a value greater than zero") | ||
) | ||
|
||
// ScraperControllerArguments defines common settings for a scraper controller | ||
// configuration. | ||
type ScraperControllerArguments struct { | ||
CollectionInterval time.Duration `river:"collection_interval,attr,optional"` | ||
InitialDelay time.Duration `river:"initial_delay,attr,optional"` | ||
Timeout time.Duration `river:"timeout,attr,optional"` | ||
} | ||
|
||
// DefaultScraperControllerArguments holds default settings for ScraperControllerArguments. | ||
var DefaultScraperControllerArguments = ScraperControllerArguments{ | ||
CollectionInterval: time.Minute, | ||
InitialDelay: time.Second, | ||
Timeout: 0 * time.Second, | ||
} | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *ScraperControllerArguments) SetToDefault() { | ||
*args = DefaultScraperControllerArguments | ||
} | ||
|
||
// Convert converts args into the upstream type. | ||
func (args *ScraperControllerArguments) Convert() *scraperhelper.ScraperControllerSettings { | ||
if args == nil { | ||
return nil | ||
} | ||
|
||
return &scraperhelper.ScraperControllerSettings{ | ||
CollectionInterval: args.CollectionInterval, | ||
InitialDelay: args.InitialDelay, | ||
Timeout: args.Timeout, | ||
} | ||
} | ||
|
||
// Validate returns an error if args is invalid. | ||
func (args *ScraperControllerArguments) Validate() error { | ||
if args.CollectionInterval <= 0 { | ||
return fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval) | ||
} | ||
if args.Timeout < 0 { | ||
return fmt.Errorf(`"timeout": %w`, errGreaterThanZero) | ||
} | ||
return nil | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package vcenter | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/river" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/vcenterreceiver" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestArguments_UnmarshalRiver(t *testing.T) { | ||
in := ` | ||
endpoint = "http://localhost:1234" | ||
username = "user" | ||
password = "pass" | ||
collection_interval = "2m" | ||
output { /* no-op */ } | ||
` | ||
|
||
var args Arguments | ||
require.NoError(t, river.Unmarshal([]byte(in), &args)) | ||
args.Convert() | ||
ext, err := args.Convert() | ||
require.NoError(t, err) | ||
otelArgs, ok := (ext).(*vcenterreceiver.Config) | ||
|
||
require.True(t, ok) | ||
|
||
require.Equal(t, "user", otelArgs.Username) | ||
require.Equal(t, "pass", string(otelArgs.Password)) | ||
require.Equal(t, "http://localhost:1234", otelArgs.Endpoint) | ||
|
||
require.Equal(t, 2*time.Minute, otelArgs.ScraperControllerSettings.CollectionInterval) | ||
require.Equal(t, time.Second, otelArgs.ScraperControllerSettings.InitialDelay) | ||
require.Equal(t, 0*time.Second, otelArgs.ScraperControllerSettings.Timeout) | ||
|
||
require.Equal(t, true, otelArgs.Metrics.VcenterClusterCPUEffective.Enabled) | ||
require.Equal(t, false, otelArgs.Metrics.VcenterVMMemoryUtilization.Enabled) | ||
require.Equal(t, true, otelArgs.ResourceAttributes.VcenterClusterName.Enabled) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.