Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cxdy authored Aug 6, 2024
2 parents 46818ea + 965ff08 commit ef3be97
Show file tree
Hide file tree
Showing 268 changed files with 943 additions and 856 deletions.
27 changes: 27 additions & 0 deletions .chloggen/codeboten_update-scope-2.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: breaking

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Update the scope name for telemetry produced by the loadbalancingexporter from otelcol/loki to github.com/open-telemetry/opentelemetry-collector-contrib/exporter/lokiexporter

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

# (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: []
13 changes: 13 additions & 0 deletions .chloggen/fix_supervisor-write-files-to-storage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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: cmd/opampsupervisor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Write the generated effective config and agent log files to the user-defined storage directory.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [34341]
28 changes: 28 additions & 0 deletions cmd/opampsupervisor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,34 @@ func TestSupervisorPersistsNewInstanceID(t *testing.T) {
require.Equal(t, newID, uuid.UUID(newRecievedAgentID))
}

func TestSupervisorWritesAgentFilesToStorageDir(t *testing.T) {
// Tests that the agent logs and effective.yaml are written under the storage directory.
storageDir := t.TempDir()

server := newOpAMPServer(
t,
defaultConnectingHandler,
server.ConnectionCallbacksStruct{},
)

s := newSupervisor(t, "basic", map[string]string{
"url": server.addr,
"storage_dir": storageDir,
})

waitForSupervisorConnection(server.supervisorConnected, true)

t.Logf("Supervisor connected")

s.Shutdown()

t.Logf("Supervisor shutdown")

// Check config and log files are written in storage dir
require.FileExists(t, filepath.Join(storageDir, "agent.log"))
require.FileExists(t, filepath.Join(storageDir, "effective.yaml"))
}

func findRandomPort() (int, error) {
l, err := net.Listen("tcp", "localhost:0")

Expand Down
7 changes: 5 additions & 2 deletions cmd/opampsupervisor/supervisor/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"sync/atomic"
"syscall"
"time"
Expand All @@ -23,16 +24,18 @@ import (
type Commander struct {
logger *zap.Logger
cfg config.Agent
logsDir string
args []string
cmd *exec.Cmd
doneCh chan struct{}
exitCh chan struct{}
running *atomic.Int64
}

func NewCommander(logger *zap.Logger, cfg config.Agent, args ...string) (*Commander, error) {
func NewCommander(logger *zap.Logger, logsDir string, cfg config.Agent, args ...string) (*Commander, error) {
return &Commander{
logger: logger,
logsDir: logsDir,
cfg: cfg,
args: args,
running: &atomic.Int64{},
Expand Down Expand Up @@ -69,7 +72,7 @@ func (c *Commander) Start(ctx context.Context) error {

c.logger.Debug("Starting agent", zap.String("agent", c.cfg.Executable))

logFilePath := "agent.log"
logFilePath := filepath.Join(c.logsDir, "agent.log")
logFile, err := os.Create(logFilePath)
if err != nil {
return fmt.Errorf("cannot create %s: %w", logFilePath, err)
Expand Down
28 changes: 17 additions & 11 deletions cmd/opampsupervisor/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var (
)

const (
persistentStateFilePath = "persistent_state.yaml"
agentConfigFilePath = "effective.yaml"
persistentStateFileName = "persistent_state.yaml"
agentConfigFileName = "effective.yaml"
)

const maxBufferedCustomMessages = 10
Expand Down Expand Up @@ -166,7 +166,7 @@ func NewSupervisor(logger *zap.Logger, configFile string) (*Supervisor, error) {
}

var err error
s.persistentState, err = loadOrCreatePersistentState(s.persistentStateFile())
s.persistentState, err = loadOrCreatePersistentState(s.persistentStateFilePath())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -197,8 +197,9 @@ func NewSupervisor(logger *zap.Logger, configFile string) (*Supervisor, error) {

s.commander, err = commander.NewCommander(
s.logger,
s.config.Storage.Directory,
s.config.Agent,
"--config", agentConfigFilePath,
"--config", s.agentConfigFilePath(),
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -278,7 +279,7 @@ func (s *Supervisor) getBootstrapInfo() (err error) {
return err
}

err = os.WriteFile(agentConfigFilePath, bootstrapConfig, 0600)
err = os.WriteFile(s.agentConfigFilePath(), bootstrapConfig, 0600)
if err != nil {
return fmt.Errorf("failed to write agent config: %w", err)
}
Expand Down Expand Up @@ -338,8 +339,9 @@ func (s *Supervisor) getBootstrapInfo() (err error) {

cmd, err := commander.NewCommander(
s.logger,
s.config.Storage.Directory,
s.config.Agent,
"--config", agentConfigFilePath,
"--config", s.agentConfigFilePath(),
)
if err != nil {
return err
Expand Down Expand Up @@ -801,7 +803,7 @@ func (s *Supervisor) loadAndWriteInitialMergedConfig() error {

// write the initial merged config to disk
cfg := s.mergedConfig.Load().(string)
if err := os.WriteFile(agentConfigFilePath, []byte(cfg), 0600); err != nil {
if err := os.WriteFile(s.agentConfigFilePath(), []byte(cfg), 0600); err != nil {
s.logger.Error("Failed to write agent config.", zap.Error(err))
}

Expand Down Expand Up @@ -1046,7 +1048,7 @@ func (s *Supervisor) healthCheck() {
}

func (s *Supervisor) runAgentProcess() {
if _, err := os.Stat(agentConfigFilePath); err == nil {
if _, err := os.Stat(s.agentConfigFilePath()); err == nil {
// We have an effective config file saved previously. Use it to start the agent.
s.logger.Debug("Effective config found, starting agent initial time")
s.startAgent()
Expand Down Expand Up @@ -1118,7 +1120,7 @@ func (s *Supervisor) stopAgentApplyConfig() {
s.logger.Error("Could not stop agent process", zap.Error(err))
}

if err := os.WriteFile(agentConfigFilePath, []byte(cfg), 0600); err != nil {
if err := os.WriteFile(s.agentConfigFilePath(), []byte(cfg), 0600); err != nil {
s.logger.Error("Failed to write agent config.", zap.Error(err))
}
}
Expand Down Expand Up @@ -1309,8 +1311,12 @@ func (s *Supervisor) processAgentIdentificationMessage(msg *protobufs.AgentIdent
return true
}

func (s *Supervisor) persistentStateFile() string {
return filepath.Join(s.config.Storage.Directory, persistentStateFilePath)
func (s *Supervisor) persistentStateFilePath() string {
return filepath.Join(s.config.Storage.Directory, persistentStateFileName)
}

func (s *Supervisor) agentConfigFilePath() string {
return filepath.Join(s.config.Storage.Directory, agentConfigFileName)
}

func (s *Supervisor) findRandomPort() (int, error) {
Expand Down
18 changes: 9 additions & 9 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ require (
go.opentelemetry.io/collector/receiver v0.106.1
go.opentelemetry.io/collector/receiver/nopreceiver v0.106.1
go.opentelemetry.io/collector/receiver/otlpreceiver v0.106.1
golang.org/x/sys v0.22.0
golang.org/x/sys v0.23.0
)

require (
Expand Down Expand Up @@ -374,7 +374,7 @@ require (
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ReneKroon/ttlcache/v2 v2.11.0 // indirect
github.com/SAP/go-hdb v1.10.1 // indirect
github.com/SAP/go-hdb v1.10.2 // indirect
github.com/SermoDigital/jose v0.9.2-0.20180104203859-803625baeddc // indirect
github.com/Showmax/go-fqdn v1.0.0 // indirect
github.com/aerospike/aerospike-client-go/v7 v7.6.0 // indirect
Expand Down Expand Up @@ -806,15 +806,15 @@ require (
go.uber.org/fx v1.18.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
Expand Down
35 changes: 18 additions & 17 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions cmd/oteltestbedcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ require (
go.opentelemetry.io/collector/receiver v0.106.1
go.opentelemetry.io/collector/receiver/otlpreceiver v0.106.1
go.uber.org/goleak v1.3.0
golang.org/x/sys v0.22.0
golang.org/x/sys v0.23.0
)

require (
Expand Down Expand Up @@ -275,14 +275,14 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
Expand Down
Loading

0 comments on commit ef3be97

Please sign in to comment.