Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaasman00 committed Oct 9, 2024
1 parent 5d32197 commit 766d19b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
36 changes: 22 additions & 14 deletions updater/internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,46 +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")
managerPath := filepath.Clean(filepath.Join(installDir, "manager.yaml"))
data, err := os.ReadFile(managerPath)
if err != nil {
return fmt.Errorf("read manager.yaml: %w", err)
Expand Down Expand Up @@ -388,6 +395,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"`
}
Expand Down
10 changes: 5 additions & 5 deletions updater/internal/state/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 766d19b

Please sign in to comment.