Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add some comments and unit test
  • Loading branch information
sjberman committed Sep 23, 2025
commit 6d7444f259273038b09e0dc1ec8bce457b466ddb
6 changes: 5 additions & 1 deletion internal/controller/nginx/config/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,18 @@ func createAddHeadersMap(name string) shared.Map {

// buildInferenceMaps creates maps for InferencePool Backends.
func buildInferenceMaps(groups []dataplane.BackendGroup) []shared.Map {
inferenceMaps := make([]shared.Map, 0)
inferenceMaps := make([]shared.Map, 0, len(groups))
for _, group := range groups {
for _, backend := range group.Backends {
if backend.EndpointPickerConfig != nil {
var defaultResult string
switch backend.EndpointPickerConfig.FailureMode {
// in FailClose mode, if the EPP is unavailable or returns an error,
// we return an invalid backend to ensure the request fails
case inference.EndpointPickerFailClose:
defaultResult = invalidBackendRef
// in FailOpen mode, if the EPP is unavailable or returns an error,
// we fall back to the upstream
case inference.EndpointPickerFailOpen:
defaultResult = backend.UpstreamName
}
Expand Down
26 changes: 25 additions & 1 deletion internal/controller/nginx/modules/test/epp.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { default as epp } from '../src/epp.js';
import { expect, describe, it, beforeEach, afterEach, vi } from 'vitest';

function makeRequest({ method = 'POST', headersIn = {}, requestText = '', variables = {} } = {}) {
function makeRequest({
method = 'POST',
headersIn = {},
args = {},
requestText = '',
variables = {},
} = {}) {
return {
method,
headersIn,
requestText,
variables,
args,
error: vi.fn(),
log: vi.fn(),
internalRedirect: vi.fn(),
Expand Down Expand Up @@ -79,4 +86,21 @@ describe('getEndpoint', () => {
expect(r.error).toHaveBeenCalledWith(expect.stringContaining('Error in ngx.fetch'));
expect(r.internalRedirect).toHaveBeenCalledWith('/foo');
});

it('preserves args in internal redirect when args are present', async () => {
const endpoint = 'http://endpoint';
globalThis.ngx = {
fetch: vi.fn().mockResolvedValue({
status: 200,
headers: { get: () => endpoint },
text: vi.fn(),
}),
};
const r = makeRequest({
variables: { epp_host: 'host', epp_port: '1234', epp_internal_path: '/foo' },
args: { a: '1', b: '2' },
});
await epp.getEndpoint(r);
expect(r.internalRedirect).toHaveBeenCalledWith('/foo?a=1&b=2');
});
});
Loading