Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/findings.go
T
jschoubben cf93d30150 Names N3 (indexer): the indexer names its own buckets from its credential's module
Its 26 `<Module>_<state>` bucket constants (candidates, manifests, verdicts, packages, taken, the
control records, pins, pending and the rest), its consumers, findings and first views were named
from the constant Module; they are now index.Bucket(cred.Module, <state>), and its words name
the state where they named the bucket.

Builds: design 47 G A-296

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 19:18:56 +01:00

49 lines
2.0 KiB
Go

package index
import (
"context"
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
)
// FindingsState is the indexer's state of its findings (design 47 G §383, §687).
const (
FindingsState = "findings"
)
// FindingWriter is the indexer's finding writer, mesh-sdk's held writer of the seat mesh-conditions' generated finding (design
// 47 G A-29, A-38): Write raises a finding, Clear clears one, Held answers the findings it holds, so the indexer reads what
// stands from the writer.
type FindingWriter interface {
Write(ctx context.Context, f mcseat.Finding) error
Clear(ctx context.Context, scope, id, kind, why string) error
Held() []mcseat.Finding
}
// keyID is an id as the parts of a key: each dot-separated part made safe for a bus key as a condition's key is (design 47 G
// A-22), so a finding's key keeps the shape it had.
func keyID(id string) string {
key := mcc.Key("x", id, "x")
return key[len("x.") : len(key)-len(".x")]
}
// observed is the indexer's finding of kind for the subject id as the seat's generated finding: a warning, its id made safe as a
// key's part, the writer completing its `since` (design 47 G §686, A-22).
func (ix *Indexer) observed(scope, id, kind, summary, headline, explanation, source string) mcseat.Finding {
id = keyID(id)
return mcseat.Finding{Scope: scope, ID: id, Kind: kind, Severity: mcseat.FindingSeverityWarning, Summary: summary, Headline: headline,
Explanation: explanation, Source: source, Observer: Module, At: ix.now().UTC(), Subject: mcseat.Subject{Scope: scope, ID: id}}
}
// clearFinding clears the finding of scope, id and kind when the writer holds it: a clear of none held says nothing.
func (ix *Indexer) clearFinding(ctx context.Context, scope, id, kind, why string) error {
id = keyID(id)
for _, f := range ix.Findings.Held() {
if f.Scope == scope && f.ID == id && f.Kind == kind {
return ix.Findings.Clear(ctx, scope, id, kind, why)
}
}
return nil
}