mirror of https://github.com/hashicorp/consul
NET-5879 - expose sameness group param on service health endpoint and move sameness group health fallback logic into HealthService RPC layer (#21096)
* NET-5879 - move the filter for non-passing to occur in the health RPC layer rather than the callers of the RPC * fix import of slices * NET-5879 - expose sameness group param on service health endpoint and move sameness group health fallback logic into HealthService RPC layer * fixing deepcopy * fix license headerspull/21107/head
parent
a975b04302
commit
9b2c1be053
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (c) HashiCorp, Inc.
|
||||||
|
// SPDX-License-Identifier: BUSL-1.1
|
||||||
|
|
||||||
|
//go:build !consulent
|
||||||
|
|
||||||
|
package consul
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-memdb"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/agent/consul/state"
|
||||||
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// getArgsForSamenessGroupMembers returns the arguments for the sameness group members if SamenessGroup
|
||||||
|
// field is set in the ServiceSpecificRequest. It returns the index of the sameness group, the arguments
|
||||||
|
// for the sameness group members and an error if any.
|
||||||
|
// If SamenessGroup is not set, it returns:
|
||||||
|
// - the index 0
|
||||||
|
// - an array containing the original arguments
|
||||||
|
// - nil error
|
||||||
|
// If SamenessGroup is set on CE, it returns::
|
||||||
|
// - the index of 0
|
||||||
|
// - nil array
|
||||||
|
// - an error indicating that sameness groups are not supported in consul CE
|
||||||
|
// If SamenessGroup is set on ENT, it returns:
|
||||||
|
// - the index of the sameness group
|
||||||
|
// - an array containing the arguments for the sameness group members
|
||||||
|
// - nil error
|
||||||
|
func (h *Health) getArgsForSamenessGroupMembers(args *structs.ServiceSpecificRequest,
|
||||||
|
ws memdb.WatchSet, state *state.Store) (uint64, []*structs.ServiceSpecificRequest, error) {
|
||||||
|
if args.SamenessGroup != "" {
|
||||||
|
return 0, nil, errors.New("sameness groups are not supported in consul CE")
|
||||||
|
}
|
||||||
|
return 0, []*structs.ServiceSpecificRequest{args}, nil
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (c) HashiCorp, Inc.
|
||||||
|
// SPDX-License-Identifier: BUSL-1.1
|
||||||
|
|
||||||
|
//go:build !consulent
|
||||||
|
|
||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hashicorp/consul/testrpc"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHealthServiceNodes_SamenessGroup_ErrorsOnCE(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("too slow for testing.Short")
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Parallel()
|
||||||
|
a := NewTestAgent(t, "")
|
||||||
|
defer a.Shutdown()
|
||||||
|
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
|
||||||
|
|
||||||
|
req, _ := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1&sameness-group=foo", nil)
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
_, err := a.srv.HealthServiceNodes(resp, req)
|
||||||
|
require.ErrorContains(t, err, "sameness groups are not supported in consul CE")
|
||||||
|
}
|
Loading…
Reference in new issue