diff --git a/updater/internal/install/install.go b/updater/internal/install/install.go index 8b7c793df..ac461b8b3 100644 --- a/updater/internal/install/install.go +++ b/updater/internal/install/install.go @@ -244,47 +244,53 @@ func skipConfigFiles(path string) bool { return false } +// SupervisorConfig describes how a supervisor is configured +type SupervisorConfig struct { + Server Server `yaml:"server"` + Capabilities Capabilities `yaml:"capabilities"` + Agent Agent `yaml:"agent"` + Storage Storage `yaml:"storage"` +} + +// Server configures how the supervisor connects to an OpAMP server +type Server struct { + Endpoint string `yaml:"endpoint"` + Headers Headers `yaml:"headers"` + TLS TLS `yaml:"tls"` +} + +// Headers are the headers the supervisor uses when interacting with the OpAMP server type Headers struct { Authorization string `yaml:"Authorization"` AgentIDFormat string `yaml:"X-Bindplane-Agent-Id-Format"` } +// TLS describes how TLS is configured when interacting with the OpAMP server type TLS struct { Insecure bool `yaml:"insecure"` InsecureSkipVerify bool `yaml:"insecure_skip_verify"` } -type Server struct { - Endpoint string `yaml:"endpoint"` - Headers Headers `yaml:"headers"` - TLS TLS `yaml:"tls"` -} - +// Capabilities are the capabilities the collector runs with type Capabilities struct { AcceptsRemoteConfig bool `yaml:"accepts_remote_config"` ReportsRemoteConfig bool `yaml:"reports_remote_config"` } +// Agent describes the agent that's ran type Agent struct { Executable string `yaml:"executable"` HealthCheckPort int `yaml:"health_check_port"` } +// Storage is where the supervisor stores various files type Storage struct { Directory string `yaml:"directory"` } -type SupervisorConfig struct { - Server Server `yaml:"server"` - Capabilities Capabilities `yaml:"capabilities"` - Agent Agent `yaml:"agent"` - Storage Storage `yaml:"storage"` -} - func translateManagerToSupervisor(logger *zap.Logger, installDir string, hcePort int, rb rollback.Rollbacker) error { // Open manager.yaml - managerPath := filepath.Join(installDir, "manager.yaml") - data, err := os.ReadFile(managerPath) + data, err := os.ReadFile(filepath.Join(installDir, "manager.yaml")) if err != nil { return fmt.Errorf("read manager.yaml: %w", err) } @@ -388,6 +394,7 @@ func writeSupervisorConfig(logger *zap.Logger, supervisorCfg *SupervisorConfig, return nil } +// PersistentState stores the ID of the collector type PersistentState struct { InstanceID string `yaml:"instance_id"` } diff --git a/updater/internal/state/monitor_test.go b/updater/internal/state/monitor_test.go index 74a51bcf0..37f1a028c 100644 --- a/updater/internal/state/monitor_test.go +++ b/updater/internal/state/monitor_test.go @@ -197,7 +197,7 @@ func TestCollectorMonitorMonitorForSuccess(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })) + testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })) defer testServer.Close() port := testServer.Listener.Addr().(*net.TCPAddr).Port @@ -213,7 +213,7 @@ func TestCollectorMonitorMonitorForSuccess(t *testing.T) { { desc: "Successful startup", testFunc: func(t *testing.T) { - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })) + testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })) defer testServer.Close() port := testServer.Listener.Addr().(*net.TCPAddr).Port @@ -235,13 +235,13 @@ func TestCollectorMonitorMonitorForSuccess(t *testing.T) { } err := collectorMonitor.MonitorForSuccess(context.Background()) - assert.ErrorContains(t, err, "connect: connection refused") + assert.ErrorContains(t, err, "failed to reach agent after 3 attempts") }, }, { desc: "Agent returns bad status", testFunc: func(t *testing.T) { - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) })) + testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusBadRequest) })) defer testServer.Close() port := testServer.Listener.Addr().(*net.TCPAddr).Port @@ -257,7 +257,7 @@ func TestCollectorMonitorMonitorForSuccess(t *testing.T) { { desc: "Agent initially fails but then succeeds", testFunc: func(t *testing.T) { - testServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })) + testServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })) port := testServer.Listener.Addr().(*net.TCPAddr).Port err := testServer.Listener.Close() require.NoError(t, err)