diff --git a/CHANGELOG.md b/CHANGELOG.md index 584a6733..e1dc71e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - Creating or updating a database with a node name that isn't "n" followed by a number, such as "n1-east", now returns a 400 error that names the node and the expected format, instead of a 500 server error. The same node name format is now enforced for the node names in backup, switchover, failover, and restore requests. - A scheduled switchover's task now stays running until the switchover happens, and canceling the task before the scheduled time cancels the switchover. Previously, the task completed as soon as the switchover was scheduled and could no longer be canceled. A scheduled switchover is now skipped if the primary changes before the scheduled time, it fails rather than running more than 5 minutes late, and it uses the node's current hosts at the scheduled time. Requesting a switchover or failover for a node that already has one in progress now returns a 409 operation_already_in_progress error instead of a 500 server error. - Replicas of Spock 6 databases on Postgres 17 or later now drop stale copies of Spock replication slots, including after a switchover or failover, so that native slot synchronization keeps their copies current. Creating or updating a replica no longer fails when its slot copies stay temporary, and an update doesn't switch over to a replica that lacks them. +- Creating or updating a database now reports every invalid service in one error instead of only the first one. On hosts that use the systemd orchestrator, the error now says when a service isn't installed, for example `service 'postgrest' is not installed on host 'host-1'`. ### Security diff --git a/changes/v1.0.0.md b/changes/v1.0.0.md index 89fff3c4..08959cee 100644 --- a/changes/v1.0.0.md +++ b/changes/v1.0.0.md @@ -32,6 +32,7 @@ - Creating or updating a database with a node name that isn't "n" followed by a number, such as "n1-east", now returns a 400 error that names the node and the expected format, instead of a 500 server error. The same node name format is now enforced for the node names in backup, switchover, failover, and restore requests. - A scheduled switchover's task now stays running until the switchover happens, and canceling the task before the scheduled time cancels the switchover. Previously, the task completed as soon as the switchover was scheduled and could no longer be canceled. A scheduled switchover is now skipped if the primary changes before the scheduled time, it fails rather than running more than 5 minutes late, and it uses the node's current hosts at the scheduled time. Requesting a switchover or failover for a node that already has one in progress now returns a 409 operation_already_in_progress error instead of a 500 server error. - Replicas of Spock 6 databases on Postgres 17 or later now drop stale copies of Spock replication slots, including after a switchover or failover, so that native slot synchronization keeps their copies current. Creating or updating a replica no longer fails when its slot copies stay temporary, and an update doesn't switch over to a replica that lacks them. +- Creating or updating a database now reports every invalid service in one error instead of only the first one. On hosts that use the systemd orchestrator, the error now says when a service isn't installed, for example `service 'postgrest' is not installed on host 'host-1'`. ### Security diff --git a/docs/changelog.md b/docs/changelog.md index 584a6733..e1dc71e1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -34,6 +34,7 @@ - Creating or updating a database with a node name that isn't "n" followed by a number, such as "n1-east", now returns a 400 error that names the node and the expected format, instead of a 500 server error. The same node name format is now enforced for the node names in backup, switchover, failover, and restore requests. - A scheduled switchover's task now stays running until the switchover happens, and canceling the task before the scheduled time cancels the switchover. Previously, the task completed as soon as the switchover was scheduled and could no longer be canceled. A scheduled switchover is now skipped if the primary changes before the scheduled time, it fails rather than running more than 5 minutes late, and it uses the node's current hosts at the scheduled time. Requesting a switchover or failover for a node that already has one in progress now returns a 409 operation_already_in_progress error instead of a 500 server error. - Replicas of Spock 6 databases on Postgres 17 or later now drop stale copies of Spock replication slots, including after a switchover or failover, so that native slot synchronization keeps their copies current. Creating or updating a replica no longer fails when its slot copies stay temporary, and an update doesn't switch over to a replica that lacks them. +- Creating or updating a database now reports every invalid service in one error instead of only the first one. On hosts that use the systemd orchestrator, the error now says when a service isn't installed, for example `service 'postgrest' is not installed on host 'host-1'`. ### Security diff --git a/e2e/rag_service_test.go b/e2e/rag_service_test.go index c0c684d5..dbfa4154 100644 --- a/e2e/rag_service_test.go +++ b/e2e/rag_service_test.go @@ -664,7 +664,7 @@ func TestProvisionRAGServiceUnsupportedVersion(t *testing.T) { require.Error(t, err, "CreateDatabase should reject an unsupported service version") assert.ErrorIs(t, err, client.ErrInvalidInput, "Error should be invalid input") assert.Nil(t, createResp, "CreateDatabase should not return a response") - assert.Contains(t, err.Error(), "does not support rag version 99.99.99", "Error should name the unsupported version") + assert.Contains(t, err.Error(), "99.99.99", "Error should name the unsupported version") t.Logf("CreateDatabase rejected as expected: %s", err) t.Log("RAG unsupported version test completed successfully") diff --git a/e2e/service_provisioning_test.go b/e2e/service_provisioning_test.go index a293c4e9..e9bc7b92 100644 --- a/e2e/service_provisioning_test.go +++ b/e2e/service_provisioning_test.go @@ -440,7 +440,7 @@ func TestProvisionMCPServiceUnsupportedVersion(t *testing.T) { require.Error(t, err, "CreateDatabase should reject an unsupported service version") assert.ErrorIs(t, err, client.ErrInvalidInput, "Error should be invalid input") assert.Nil(t, createResp, "CreateDatabase should not return a response") - assert.Contains(t, err.Error(), "does not support mcp version 99.99.99", "Error should name the unsupported version") + assert.Contains(t, err.Error(), "99.99.99", "Error should name the unsupported version") t.Logf("CreateDatabase rejected as expected: %s", err) @@ -556,7 +556,7 @@ func TestProvisionMCPServiceRecovery(t *testing.T) { }) require.Error(t, err, "UpdateDatabase should reject an unsupported service version") assert.ErrorIs(t, err, client.ErrInvalidInput, "Error should be invalid input") - assert.Contains(t, err.Error(), "does not support mcp version 99.99.99", "Error should name the unsupported version") + assert.Contains(t, err.Error(), "99.99.99", "Error should name the unsupported version") t.Logf("UpdateDatabase rejected as expected: %s", err) // The rejected update must not have been applied diff --git a/server/internal/database/service.go b/server/internal/database/service.go index a7d24176..39f805c2 100644 --- a/server/internal/database/service.go +++ b/server/internal/database/service.go @@ -665,19 +665,23 @@ func (s *Service) PopulateSpecDefaults(ctx context.Context, spec, current *Spec) } // validateServiceHosts validates that every service's host IDs refer to -// registered hosts that can run the requested service version. +// registered hosts that can run the requested service version. It returns +// every problem it finds, rather than only the first one. func validateServiceHosts(services []*ServiceSpec, hostsByID map[string]*host.Host) error { + var errs []error for _, svc := range services { var knownHosts []*host.Host for _, hostID := range svc.HostIDs { h, ok := hostsByID[hostID] if !ok { - return fmt.Errorf("service %q: host %s not found", svc.ServiceID, hostID) + errs = append(errs, fmt.Errorf("service %q: host %s not found", svc.ServiceID, hostID)) + continue } if h.Orchestrator == config.OrchestratorSystemD && svc.Port == nil { // systemd service instances listen on the host directly, so // they're unreachable without a port. - return fmt.Errorf("service %q: port is required for host %s, which uses the systemd orchestrator. set it to 0 to assign a random port", svc.ServiceID, h.ID) + errs = append(errs, fmt.Errorf("service %q: port is required for host %s, which uses the systemd orchestrator. set it to 0 to assign a random port", svc.ServiceID, h.ID)) + continue } if h.SupportedServices == nil { // This host's record was written by a Control Plane version @@ -690,7 +694,8 @@ func validateServiceHosts(services []*ServiceSpec, hostsByID map[string]*host.Ho continue } if !h.SupportsService(svc.ServiceType, svc.Version) { - return fmt.Errorf("service %q: host %s does not support %s version %s", svc.ServiceID, h.ID, svc.ServiceType, svc.Version) + errs = append(errs, unsupportedServiceError(svc, h)) + continue } knownHosts = append(knownHosts, h) } @@ -699,12 +704,26 @@ func validateServiceHosts(services []*ServiceSpec, hostsByID map[string]*host.Ho // hosts' defaults, but each host resolves it to its own default, // so they must agree for every instance to run the same version. if _, err := host.CommonDefaultServiceVersion(svc.ServiceType, knownHosts...); err != nil { - return fmt.Errorf("service %q: unable to resolve version %s: %w", svc.ServiceID, svc.Version, err) + errs = append(errs, fmt.Errorf("service %q: unable to resolve version %s: %w", svc.ServiceID, svc.Version, err)) } } } - return nil + return errors.Join(errs...) +} + +// unsupportedServiceError returns the error for a host that can't run the +// given service version. A systemd host only supports the version of each +// service that's installed on it, while a swarm host supports the versions in +// the version manifest. +func unsupportedServiceError(svc *ServiceSpec, h *host.Host) error { + if h.Orchestrator != config.OrchestratorSystemD { + return fmt.Errorf("service %q: host %s does not support %s version %s", svc.ServiceID, h.ID, svc.ServiceType, svc.Version) + } + if svc.Version == host.ServiceVersionLatest { + return fmt.Errorf("service '%s' is not installed on host '%s'", svc.ServiceType, h.ID) + } + return fmt.Errorf("service '%s' version '%s' is not installed on host '%s'", svc.ServiceType, svc.Version, h.ID) } func (s *Service) ReconcileInstanceSpec(ctx context.Context, spec *InstanceSpec) (*InstanceSpec, error) { diff --git a/server/internal/database/spec_internal_test.go b/server/internal/database/spec_internal_test.go index e63e6a8b..318c73f8 100644 --- a/server/internal/database/spec_internal_test.go +++ b/server/internal/database/spec_internal_test.go @@ -2,6 +2,7 @@ package database import ( "maps" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -165,6 +166,12 @@ func TestValidateServiceHosts(t *testing.T) { SupportedServices: map[string][]string{"postgrest": {"14.5"}}, DefaultServiceVersions: map[string]string{"postgrest": "14.5"}, }, + "host-systemd-2": { + ID: "host-systemd-2", + Orchestrator: config.OrchestratorSystemD, + SupportedServices: map[string][]string{}, + DefaultServiceVersions: map[string]string{}, + }, } postgrest := func(version string, hostIDs ...string) *ServiceSpec { return &ServiceSpec{ @@ -219,7 +226,16 @@ func TestValidateServiceHosts(t *testing.T) { svc.OrchestratorOpts = &OrchestratorOpts{Swarm: &SwarmOpts{Image: "registry.example.com/postgrest:dev"}} return svc }(), - expectedErr: `service "api": host host-systemd does not support postgrest version 99.0`, + expectedErr: `service 'postgrest' version '99.0' is not installed on host 'host-systemd'`, + }, + { + name: "service not installed on a systemd host", + service: func() *ServiceSpec { + svc := postgrest("latest", "host-systemd-2") + svc.Port = utils.PointerTo(0) + return svc + }(), + expectedErr: `service 'postgrest' is not installed on host 'host-systemd-2'`, }, { name: "host without supported services is not validated", @@ -253,6 +269,26 @@ func TestValidateServiceHosts(t *testing.T) { } }) } + + t.Run("returns every error", func(t *testing.T) { + mcp := &ServiceSpec{ + ServiceID: "mcp-server", + ServiceType: "mcp", + Version: "latest", + HostIDs: []string{"host-systemd", "host-systemd-2"}, + Port: utils.PointerTo(0), + } + api := postgrest("latest", "host-systemd", "host-systemd-2", "host-5") + api.Port = utils.PointerTo(0) + + err := validateServiceHosts([]*ServiceSpec{api, mcp}, hostsByID) + assert.EqualError(t, err, strings.Join([]string{ + `service 'postgrest' is not installed on host 'host-systemd-2'`, + `service "api": host host-5 not found`, + `service 'mcp' is not installed on host 'host-systemd'`, + `service 'mcp' is not installed on host 'host-systemd-2'`, + }, "\n")) + }) } func TestValidateSpockRequirements(t *testing.T) {