mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2026-06-19 07:36:59 +00:00
c4259c15e2
The advanced log search filters were almost entirely non-functional:
- The status filter issued a text term query against the numeric
"status" field, so it never matched any document.
- The IP and method filters used the field names "remote_addr" and
"request_method", which do not exist in the index ("ip" / "method").
- The path, user agent, referer, browser, OS and device filters were
never wired into the query builder.
Faceting on the numeric "status" field also used a terms facet, which
cannot bucket a numeric field and produced garbage prefix-coded terms.
Changes:
- Correct the IP and method field names in the query builder.
- Match status codes with inclusive numeric range queries.
- Wire in the missing path / user agent / referer (match phrase) and
browser / OS / device (term) filters.
- Split comma-joined browser/OS/device values in the search handler so
multi-select works.
- Facet the numeric status field with numeric ranges so the status
code distribution is accurate.
- Add regression tests covering every filter and the status facet
against a real Bleve index.
Closes #1669
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
31 lines
961 B
Go
31 lines
961 B
Go
package nginx_log
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TestSplitCommaSeparated verifies that comma-joined filter values produced by
|
|
// the frontend multi-select inputs (browser/os/device) are split back into
|
|
// individual values so each can be matched independently.
|
|
func TestSplitCommaSeparated(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want []string
|
|
}{
|
|
{"single value", "Chrome", []string{"Chrome"}},
|
|
{"multiple values", "Chrome,Firefox", []string{"Chrome", "Firefox"}},
|
|
{"values containing spaces", "Internet Explorer,Samsung Browser", []string{"Internet Explorer", "Samsung Browser"}},
|
|
{"trims surrounding whitespace", " Chrome , Firefox ", []string{"Chrome", "Firefox"}},
|
|
{"drops empty segments", "Chrome,,Firefox,", []string{"Chrome", "Firefox"}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, tt.want, splitCommaSeparated(tt.input))
|
|
})
|
|
}
|
|
}
|