#53430·beats

[bug-hunter] ES state store fails for mixed-case or spaced Filebeat input IDs

Author: github-actions[bot]Created Sep 28, 2026Updated Sep 28, 2026
Labelsneeds_team

Impact

When Elasticsearch-backed cursor state storage is enabled for Filebeat inputs, a configured input id containing uppercase letters or spaces causes state writes to fail with invalid_index_name_exception. This breaks cursor persistence, which can lead to re-reading data and duplicate ingestion after restarts.

This became user-facing after the recent per-input ES state store scoping change in eda1030a14.

Reproduction Steps

  1. Create a minimal repro module:
    bash
    mkdir -p /tmp/gh-aw/agent/es-store-repro
    cat > /tmp/gh-aw/agent/es-store-repro/go.mod <<'GOMOD'
    module esstorerepro
    
    go 1.26
    
    require github.com/elastic/beats/v7 v7.0.0
    
    replace github.com/elastic/beats/v7 => /home/runner/work/beats/beats
    GOMOD
  2. Add this failing test at /tmp/gh-aw/agent/es-store-repro/repro_failing_test.go:
    go
    package esstorerepro
    
    import (
         "context"
         "net/http"
         "net/http/httptest"
         "strings"
         "testing"
    
         "github.com/elastic/beats/v7/libbeat/esleg/eslegclient"
         esstore "github.com/elastic/beats/v7/libbeat/statestore/backend/es"
         "github.com/elastic/elastic-agent-libs/logp/logptest"
    )
    
    // This test encodes the expected product behavior: accepted input IDs should not
    // break cursor persistence when Elasticsearch state store is enabled.
    func TestExpectedAcceptedInputIDToPersistState(t *testing.T) {
         server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
             if r.URL.Path == "/" {
                 w.Header().Set("Content-Type", "application/json")
                 _, _ = w.Write([]byte(`{"version":{"number":"8.16.0"}}`))
                 return
             }
             if r.Method == http.MethodPut {
                 parts := strings.Split(strings.TrimPrefix(r.URL.Path, "/"), "/")
                 if len(parts) > 0 {
                     index := parts[0]
                     if strings.Contains(index, " ") || index != strings.ToLower(index) {
                         w.WriteHeader(http.StatusBadRequest)
                         _, _ = w.Write([]byte(`{"error":{"type":"invalid_index_name_exception","reason":"Invalid index name"},"status":400}`))
                         return
                     }
                 }
             }
             w.Header().Set("Content-Type", "application/json")
             _, _ = w.Write([]byte(`{"result":"created"}`))
         }))
         defer server.Close()
    
         conn, err := eslegclient.NewConnection(eslegclient.ConnectionSettings{URL: server.URL}, logptest.NewTestingLogger(t, ""))
         if err != nil {
             t.Fatalf("creating es connection failed: %v", err)
         }
         if err := conn.Connect(context.Background()); err != nil {
             t.Fatalf("connect failed: %v", err)
         }
    
         store := esstore.NewStore(context.Background(), logptest.NewTestingLogger(t, ""), conn, "My Input")
         if err := store.Set("cursor", map[string]any{"offset": 1}); err != nil {
             t.Fatalf("expected state write to succeed for accepted input id, got %v", err)
         }
    }
  3. Run:
    bash
    cd /tmp/gh-aw/agent/es-store-repro
    GOWORK=off go mod tidy
    GOWORK=off go test -run TestExpectedAcceptedInputIDToPersistState -v ./...

Expected vs Actual

Expected: Cursor state write succeeds for accepted Filebeat input IDs.

Actual: State write fails because the ID is used directly in the ES index name:

=== RUN   TestExpectedAcceptedInputIDToPersistState
... PUT (127.0.0.1/redacted) Input/_doc/cursor ...
repro_failing_test.go:50: expected state write to succeed for accepted input id, got 400 Bad Request: {"error":{"type":"invalid_index_name_exception","reason":"Invalid index name"},"status":400}
--- FAIL: TestExpectedAcceptedInputIDToPersistState (0.00s)
FAIL

Failing Test

(See full test above in Reproduction Steps step 2.)

Evidence

  • filebeat/beater/store.go:162-165 calls s.shared.esRegistry.Get(s.esStoreName(id)) for ES-backed stores.
  • filebeat/beater/store.go:181-185 returns raw id as store name (no normalization/validation).
  • libbeat/statestore/backend/es/base.go:45-47 builds index as "agentless-state-" + name.
  • libbeat/statestore/backend/es/base.go:161 writes directly to /%s/_doc/%s using that index.
  • Config/tests currently accept IDs with spaces/uppercase:
    • filebeat/input/filestream/config_test.go:193-205 (id: 'some id', unpack succeeds)
    • filebeat/input/filestream/config_test.go:554 (id: unique-ID in test configs)
  • Recent change introducing per-input ES scoping: eda1030a14 (statestore: scope the Elasticsearch state store by input id).

Suggested Actions

  • Validate or normalize input IDs before deriving ES state store index names.
  • Add a focused unit test covering ID-to-index mapping constraints for ES-backed state store.
  • Document ID constraints when ES state store is enabled if normalization is not adopted.

What is this? | From workflow: Bug Hunter

Give us feedback! React with if perfect, if helpful, if not.

  • expires on Oct 5, 2026, 11:21 AM UTC