Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11.4
version: v2.12.2
args: --timeout=4m
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ linters:
- godox
- goheader
- gomoddirectives
- gomodguard
- gomodguard_v2
- goprintffuncname
- gosec
- importas
Expand All @@ -40,6 +40,13 @@ linters:
- wrapcheck
- wsl_v5
settings:
goconst:
# Test fixtures legitimately repeat string literals.
ignore-tests: true
# Common serialization keys and metric label names that mean different
# things in different contexts, so a shared constant would be misleading.
ignore-string-values:
- ^(type|name|index|query|rel)$
godox:
keywords:
- FIXME
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/opensearch-project/opensearch-go/v2 v2.3.0
github.com/ory/dockertest/v3 v3.12.0
github.com/prometheus/client_golang v1.23.2
github.com/ttab/elephant-api v0.23.0
github.com/ttab/elephant-api v0.24.1
github.com/ttab/elephantine v0.27.1
github.com/ttab/eltest v0.2.2
github.com/ttab/flerr v0.1.0
Expand All @@ -32,7 +32,6 @@ require (
github.com/twitchtv/twirp v8.1.3+incompatible
github.com/urfave/cli/v3 v3.9.0
github.com/viccon/sturdyc v1.1.5
golang.org/x/exp v0.0.0-20260603202125-055de637280b
golang.org/x/oauth2 v0.36.0
golang.org/x/sync v0.20.0
google.golang.org/protobuf v1.36.11
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tinylib/msgp v1.5.0 h1:GWnqAE54wmnlFazjq2+vgr736Akg58iiHImh+kPY2pc=
github.com/tinylib/msgp v1.5.0/go.mod h1:cvjFkb4RiC8qSBOPMGPSzSAx47nAsfhLVTCZZNuHv5o=
github.com/ttab/elephant-api v0.23.0 h1:tuZ47+3gqqKOGVaFsWFo2JsEiwjFZgypEvE5s7a9hP0=
github.com/ttab/elephant-api v0.23.0/go.mod h1:4yLd0PwZRjsRj0Lb7QSQPaoYvz0zYZ7fALe1ANaYOhg=
github.com/ttab/elephant-api v0.24.1 h1:nxBM8ZRbAjcqnxhplqP9GuWZ5EwTsK3t4eozLj9niwU=
github.com/ttab/elephant-api v0.24.1/go.mod h1:4yLd0PwZRjsRj0Lb7QSQPaoYvz0zYZ7fALe1ANaYOhg=
github.com/ttab/elephantine v0.27.1 h1:kDX9KsPBT4r9DUN3iRqFxhnhA71t3nMTKJbmvCtat14=
github.com/ttab/elephantine v0.27.1/go.mod h1:z6v4f7dEiAeOydoHAJ2HkJ6eAjTgvF8HBTOxE73NY1k=
github.com/ttab/eltest v0.2.2 h1:T9+XZdLQJQciy7U/Q+TZskaxpnwdRJKEtaSz0699H+4=
Expand Down Expand Up @@ -333,8 +333,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
golang.org/x/exp v0.0.0-20260603202125-055de637280b h1:v1uXiEBHo8QA0LiGCo7UgHMzHT4Kdfpl2zmtH5vaP1Q=
golang.org/x/exp v0.0.0-20260603202125-055de637280b/go.mod h1:d2fgXJLVs4dYDHUk5lwMIfzRzSrWCfGZb0ZqeLa/Vcw=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand Down
2 changes: 1 addition & 1 deletion index/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"fmt"
"html"
"slices"
"strings"
"time"

"github.com/microcosm-cc/bluemonday"
"github.com/ttab/elephant-index/internal"
"github.com/ttab/newsdoc"
"github.com/ttab/revisor"
"golang.org/x/exp/slices"
)

// Fields can depend on index settings (like custom normalisers). These won't be
Expand Down
2 changes: 1 addition & 1 deletion index/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func testingAPIServer(
elephantine.LogKeyComponent, "schema-loader"), schemas)
test.Must(t, err, "create schema loader")

metrics, err := index.NewMetrics(prometheus.DefaultRegisterer)
metrics, err := index.NewMetrics(reg)
test.Must(t, err, "set up metrics")

appExited := make(chan struct{})
Expand Down
2 changes: 1 addition & 1 deletion index/document.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package index

import (
"slices"
"strconv"
"time"

"github.com/ttab/newsdoc"
"golang.org/x/exp/slices"
)

// DocumentState is the full state that we want to index.
Expand Down
3 changes: 0 additions & 3 deletions index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/jackc/pgx/v5/pgxpool"
"github.com/opensearch-project/opensearch-go/v2"
"github.com/ttab/elephant-api/newsdoc"
"github.com/ttab/elephant-api/repository"
"github.com/ttab/elephant-index/internal"
"github.com/ttab/elephant-index/postgres"
Expand Down Expand Up @@ -197,8 +196,6 @@ type enrichJob struct {
UUID string
Operation int
State *DocumentState
doc *newsdoc.Document
metadoc *newsdoc.Document
fields map[string][]string
}

Expand Down
53 changes: 30 additions & 23 deletions index/index_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ func (iw *indexWorker) loop(ctx context.Context) {
func (iw *indexWorker) enrich(
job *enrichJob,
) (*DocumentState, error) {
state := DocumentState{
Heads: make(map[string]Status),
}

if job.Operation == opDelete {
return &state, nil
return &DocumentState{
Heads: make(map[string]Status),
}, nil
}

ctx, cancel := context.WithTimeout(job.ctx, 5*time.Second)
Expand All @@ -145,22 +143,35 @@ func (iw *indexWorker) enrich(
return nil, fmt.Errorf("get document: %w", err)
}

job.doc = docRes.Document

if docRes.Meta != nil {
job.metadoc = docRes.Meta.Document
}

metaRes, err := iw.idx.documents.GetMeta(ctx, &repository.GetMetaRequest{
Uuid: job.UUID,
})
if err != nil {
return nil, fmt.Errorf("get document metadata: %w", err)
}

state.CurrentVersion = metaRes.Meta.CurrentVersion
state.WorkflowState = metaRes.Meta.WorkflowState
state.WorkflowCheckpoint = metaRes.Meta.WorkflowCheckpoint
state, err := newDocumentState(docRes, metaRes)
if err != nil {
return nil, err
}

return state, nil
}

// newDocumentState assembles the indexable document state from a repository
// document and its metadata.
func newDocumentState(
docRes *repository.GetDocumentResponse,
metaRes *repository.GetMetaResponse,
) (*DocumentState, error) {
state := DocumentState{
Heads: make(map[string]Status),
CurrentVersion: metaRes.Meta.CurrentVersion,
WorkflowState: metaRes.Meta.WorkflowState,
WorkflowCheckpoint: metaRes.Meta.WorkflowCheckpoint,
Creator: metaRes.Meta.CreatorUri,
Updater: metaRes.Meta.UpdaterUri,
}

created, err := time.Parse(time.RFC3339, metaRes.Meta.Created)
if err != nil {
Expand All @@ -170,14 +181,12 @@ func (iw *indexWorker) enrich(

modified, err := time.Parse(time.RFC3339, metaRes.Meta.Modified)
if err != nil {
return nil, fmt.Errorf("parse document created time: %w",
return nil, fmt.Errorf("parse document modified time: %w",
err)
}

state.Created = created
state.Creator = metaRes.Meta.CreatorUri
state.Modified = modified
state.Updater = metaRes.Meta.UpdaterUri

for _, v := range metaRes.Meta.Acl {
state.ACL = append(state.ACL, ACLEntry{
Expand All @@ -193,21 +202,19 @@ func (iw *indexWorker) enrich(
name, err)
}

status := Status{
state.Heads[name] = Status{
ID: v.Id,
Version: v.Version,
Creator: v.Creator,
Created: created,
Meta: v.Meta,
}

state.Heads[name] = status
}

state.Document = newsdoc.DocumentFromRPC(job.doc)
state.Document = newsdoc.DocumentFromRPC(docRes.Document)

if job.metadoc != nil {
md := newsdoc.DocumentFromRPC(job.metadoc)
if docRes.Meta != nil {
md := newsdoc.DocumentFromRPC(docRes.Meta.Document)

state.MetaDocument = &md
}
Expand Down
7 changes: 7 additions & 0 deletions index/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const (
ScopeSearch = "search"
)

// HTTP header names.
const (
// headerAuthorization carries the bearer token.
headerAuthorization = "Authorization"
headerContentType = "Content-Type"
)

func RequireAnyScope(ctx context.Context, scopes ...string) (*elephantine.AuthInfo, error) {
auth, ok := elephantine.GetAuthInfo(ctx)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion index/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (ep *ElasticProxy) searchHandler(
) (outErr error) {
ctx := r.Context()

authorization := r.Header.Get("Authorization")
authorization := r.Header.Get(headerAuthorization)
if authorization == "" {
return ElasticErrorf(
ErrorTypeUnauthorized,
Expand Down
2 changes: 1 addition & 1 deletion index/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"encoding/json"
"fmt"
"log/slog"
"maps"
"sync"
"time"

"github.com/ttab/elephant-api/repository"
"github.com/ttab/elephantine"
"github.com/ttab/revisor"
"golang.org/x/exp/maps"
)

type SchemaLoader struct {
Expand Down
2 changes: 1 addition & 1 deletion index/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func ElasticHandler(
ee = e
}

w.Header().Set("Content-Type", "application/json")
w.Header().Set(headerContentType, "application/json")
w.WriteHeader(ee.Status)

enc := json.NewEncoder(w)
Expand Down
Loading