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

chore: Merge release/v1.63.0 in prep for release #1937

Merged
merged 12 commits into from
Oct 29, 2024
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
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# @dpaasman00 and @BinaryFissionGames are the main codeowners of this repository but anyone from @observIQ/platform can approve PRs.
* @dpaasman00 @BinaryFissionGames @observIQ/platform
# @dpaasman00 is the main codeowner of this repository but anyone from @observIQ/platform can approve PRs.
* @dpaasman00 @observIQ/platform
30 changes: 23 additions & 7 deletions cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"strconv"
_ "time/tzdata"

"github.com/google/uuid"
"github.com/observiq/bindplane-agent/collector"
"github.com/observiq/bindplane-agent/internal/logging"
"github.com/observiq/bindplane-agent/internal/service"
"github.com/observiq/bindplane-agent/internal/version"
"github.com/observiq/bindplane-agent/opamp"
"github.com/oklog/ulid/v2"
"github.com/spf13/pflag"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -179,9 +179,19 @@ func checkManagerConfig(configPath *string) error {
return statErr
}

newConfig.AgentID, ok = os.LookupEnv(agentIDENV)
if !ok {
newConfig.AgentID = ulid.Make().String()
if envString, ok := os.LookupEnv(agentIDENV); ok {
var err error
newConfig.AgentID, err = opamp.ParseAgentID(envString)
if err != nil {
return fmt.Errorf("invalid agent ID in env %q: %w", agentIDENV, err)
}
} else {
u, err := uuid.NewV7()
if err != nil {
return fmt.Errorf("new uuidv7: %w", err)
}

newConfig.AgentID = opamp.AgentIDFromUUID(u)
}

if sk, ok := os.LookupEnv(secretkeyENV); ok {
Expand Down Expand Up @@ -231,12 +241,18 @@ func ensureIdentity(configPath string) error {
return fmt.Errorf("unable to interpret config file: %w", err)
}

// If the AgentID is not a ULID (legacy ID or empty) then we need to generate a ULID as the AgentID.
if _, err := ulid.Parse(candidateConfig.AgentID); err == nil {
// If the AgentID is empty then we need to generate a new ID as the AgentID.
if candidateConfig.AgentID != opamp.EmptyAgentID {
return nil
}

candidateConfig.AgentID = ulid.Make().String()
u, err := uuid.NewV7()
if err != nil {
return fmt.Errorf("new uuidv7: %w", err)
}

candidateConfig.AgentID = opamp.AgentIDFromUUID(u)

newBytes, err := yaml.Marshal(candidateConfig)
if err != nil {
return fmt.Errorf("failed to marshal sanitized config: %w", err)
Expand Down
32 changes: 17 additions & 15 deletions cmd/collector/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand All @@ -30,6 +29,14 @@ import (
"gopkg.in/yaml.v3"
)

// Must is a helper function for tests that panics if there is an error creating the object of type T
func Must[T any](t T, err error) T {
if err != nil {
panic(err)
}
return t
}

func TestGetDefaultCollectorConfigPathENV(t *testing.T) {
fakeConfigPath := "./fake/path/config.yaml"

Expand Down Expand Up @@ -99,7 +106,7 @@ func TestCheckManagerConfigNoFile(t *testing.T) {

t.Setenv(agentNameENV, "agent name")

t.Setenv(agentIDENV, "agent ID")
t.Setenv(agentIDENV, "01HX2DWEQZ045KQR3VG0EYEZ94")

t.Setenv(secretkeyENV, "secretKey")

Expand All @@ -113,7 +120,7 @@ func TestCheckManagerConfigNoFile(t *testing.T) {
actual, _ := opamp.ParseConfig(manager)
expected := &opamp.Config{
Endpoint: "0.0.0.0",
AgentID: "agent ID",
AgentID: Must(opamp.ParseAgentID("01HX2DWEQZ045KQR3VG0EYEZ94")),
AgentName: new(string),
SecretKey: new(string),
Labels: new(string),
Expand Down Expand Up @@ -244,23 +251,20 @@ func TestManagerConfigNoAgentIDWillSet(t *testing.T) {
err := checkManagerConfig(&manager)
require.NoError(t, err)

cfgBytes, err := ioutil.ReadFile(manager)
cfgBytes, err := os.ReadFile(manager)
require.NoError(t, err)

var config opamp.Config
require.NoError(t, yaml.Unmarshal(cfgBytes, &config))
require.NotEmpty(t, config.AgentID)
ulidID, err := ulid.Parse(config.AgentID)
require.NoError(t, err)
require.NotEmpty(t, ulidID)
require.NotEqual(t, opamp.EmptyAgentID, config.AgentID)
}

// TestManagerConfigWillNotOverwriteCurrentAgentID tests that if the agent ID is a ULID it will not overwrite it
func TestManagerConfigWillNotOverwriteCurrentAgentID(t *testing.T) {
tmpDir := t.TempDir()
manager := filepath.Join(tmpDir, "manager.yaml")

id := ulid.Make().String()
id := ulid.Make()
data := []byte(fmt.Sprintf(`
---
agent_id: %s
Expand All @@ -269,12 +273,12 @@ agent_id: %s
err := checkManagerConfig(&manager)
require.NoError(t, err)

cfgBytes, err := ioutil.ReadFile(manager)
cfgBytes, err := os.ReadFile(manager)
require.NoError(t, err)

var config opamp.Config
require.NoError(t, yaml.Unmarshal(cfgBytes, &config))
require.Equal(t, config.AgentID, id)
require.Equal(t, config.AgentID.String(), id.String())
}

// TestManagerConfigWillUpdateLegacyAgentID tests that if the agent ID is a Legacy ID (UUID format) it will overwrite with a new ULID
Expand All @@ -291,14 +295,12 @@ agent_id: %s
err := checkManagerConfig(&manager)
require.NoError(t, err)

cfgBytes, err := ioutil.ReadFile(manager)
cfgBytes, err := os.ReadFile(manager)
require.NoError(t, err)

var config opamp.Config
require.NoError(t, yaml.Unmarshal(cfgBytes, &config))
_, err = ulid.Parse(config.AgentID)
require.NoError(t, err)
require.NotEqual(t, config.AgentID, legacyID)
require.NotEqual(t, opamp.EmptyAgentID, config.AgentID)
}

func TestManagerConfigWillErrorOnInvalidOpAmpConfig(t *testing.T) {
Expand Down
128 changes: 65 additions & 63 deletions cmd/plugindocgen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/observiq/bindplane-agent/plugindocgen
go 1.22.6

require (
github.com/observiq/bindplane-agent/receiver/pluginreceiver v1.62.0
github.com/observiq/bindplane-agent/receiver/pluginreceiver v1.63.0
github.com/spf13/pflag v1.0.5
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -19,14 +19,14 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.10 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
Expand All @@ -36,10 +36,10 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage v0.111.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage v0.112.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.20.4 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.60.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand All @@ -50,71 +50,73 @@ require (
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
go.opentelemetry.io/collector v0.111.0 // indirect
go.opentelemetry.io/collector/component v0.111.0 // indirect
go.opentelemetry.io/collector/component/componentprofiles v0.111.0 // indirect
go.opentelemetry.io/collector/component/componentstatus v0.111.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.111.0 // indirect
go.opentelemetry.io/collector/confmap v1.17.0 // indirect
go.opentelemetry.io/collector/confmap/provider/envprovider v1.17.0 // indirect
go.opentelemetry.io/collector/confmap/provider/fileprovider v1.17.0 // indirect
go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.17.0 // indirect
go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.17.0 // indirect
go.opentelemetry.io/collector/connector v0.111.0 // indirect
go.opentelemetry.io/collector/connector/connectorprofiles v0.111.0 // indirect
go.opentelemetry.io/collector/consumer v0.111.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.111.0 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.111.0 // indirect
go.opentelemetry.io/collector/exporter v0.111.0 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.111.0 // indirect
go.opentelemetry.io/collector/extension v0.111.0 // indirect
go.opentelemetry.io/collector/extension/experimental/storage v0.111.0 // indirect
go.opentelemetry.io/collector/extension/extensioncapabilities v0.111.0 // indirect
go.opentelemetry.io/collector/featuregate v1.17.0 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.111.0 // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.0 // indirect
go.opentelemetry.io/collector/otelcol v0.111.0 // indirect
go.opentelemetry.io/collector/pdata v1.17.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.111.0 // indirect
go.opentelemetry.io/collector/pdata/testdata v0.111.0 // indirect
go.opentelemetry.io/collector/pipeline v0.111.0 // indirect
go.opentelemetry.io/collector/processor v0.111.0 // indirect
go.opentelemetry.io/collector/processor/processorprofiles v0.111.0 // indirect
go.opentelemetry.io/collector/receiver v0.111.0 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.0 // indirect
go.opentelemetry.io/collector/semconv v0.111.0 // indirect
go.opentelemetry.io/collector/service v0.111.0 // indirect
go.opentelemetry.io/collector v0.112.0 // indirect
go.opentelemetry.io/collector/component v0.112.0 // indirect
go.opentelemetry.io/collector/component/componentstatus v0.112.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.112.0 // indirect
go.opentelemetry.io/collector/confmap v1.18.0 // indirect
go.opentelemetry.io/collector/confmap/provider/envprovider v1.18.0 // indirect
go.opentelemetry.io/collector/confmap/provider/fileprovider v1.18.0 // indirect
go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.18.0 // indirect
go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.18.0 // indirect
go.opentelemetry.io/collector/connector v0.112.0 // indirect
go.opentelemetry.io/collector/connector/connectorprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/connector/connectortest v0.112.0 // indirect
go.opentelemetry.io/collector/consumer v0.112.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.112.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.112.0 // indirect
go.opentelemetry.io/collector/exporter v0.112.0 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/exporter/exportertest v0.112.0 // indirect
go.opentelemetry.io/collector/extension v0.112.0 // indirect
go.opentelemetry.io/collector/extension/experimental/storage v0.112.0 // indirect
go.opentelemetry.io/collector/extension/extensioncapabilities v0.112.0 // indirect
go.opentelemetry.io/collector/featuregate v1.18.0 // indirect
go.opentelemetry.io/collector/otelcol v0.112.0 // indirect
go.opentelemetry.io/collector/pdata v1.18.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.112.0 // indirect
go.opentelemetry.io/collector/pdata/testdata v0.112.0 // indirect
go.opentelemetry.io/collector/pipeline v0.112.0 // indirect
go.opentelemetry.io/collector/pipeline/pipelineprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/processor v0.112.0 // indirect
go.opentelemetry.io/collector/processor/processorprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/processor/processortest v0.112.0 // indirect
go.opentelemetry.io/collector/receiver v0.112.0 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.112.0 // indirect
go.opentelemetry.io/collector/semconv v0.112.0 // indirect
go.opentelemetry.io/collector/service v0.112.0 // indirect
go.opentelemetry.io/contrib/config v0.10.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.30.0 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.6.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.52.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.6.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.30.0 // indirect
go.opentelemetry.io/otel/log v0.6.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.6.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.31.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.7.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.53.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.7.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.31.0 // indirect
go.opentelemetry.io/otel/log v0.7.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.7.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
gonum.org/v1/gonum v0.15.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

Expand Down
Loading
Loading