G findings: artifact-store-tools and mesh-config read what their held writer holds, so a restart neither drops nor rewrites their findings
Their in-memory open sets go. Builds: design 47 G A-32, A-29, A-38
This commit is contained in:
@@ -86,10 +86,9 @@ type Config struct {
|
||||
Logf func(format string, a ...any)
|
||||
|
||||
mu sync.Mutex
|
||||
// Findings is the module's finding writer (design 47 G §689); nil, no finding is said. findMu guards the findings open.
|
||||
// Findings is the module's finding writer (design 47 G §689); nil, no finding is said. findMu serializes a pass over what it holds.
|
||||
Findings FindingsWriter
|
||||
findMu sync.Mutex
|
||||
open map[string]openFinding
|
||||
// withheld is why the newest list of predefined keys was not published, empty when it was (publish).
|
||||
withheld string
|
||||
|
||||
|
||||
@@ -72,20 +72,15 @@ func windowHeld(r Rename, node string, at time.Time) meshconditions.Finding {
|
||||
fmt.Sprintf("the window opened %s and %s has not reported a build reading %s", r.Nodes[node].Since.UTC().Format(time.RFC3339), node, r.To), at)
|
||||
}
|
||||
|
||||
// FindingsWriter is the module's finding writer (views.Writer), through which mesh-config writes and clears its findings
|
||||
// (design 47 G §689).
|
||||
// FindingsWriter is the module's held finding writer (views.HeldWriter), through which mesh-config writes and clears its
|
||||
// findings and reads what it holds (design 47 G §689, A-29, A-38): the module keeps no set of its own.
|
||||
type FindingsWriter interface {
|
||||
Write(ctx context.Context, finding meshconditions.Finding) error
|
||||
Clear(ctx context.Context, scope, id, kind, why string) error
|
||||
Held() []meshconditions.Finding
|
||||
}
|
||||
|
||||
// openFinding is a finding written and not yet cleared, with the parts of its id.
|
||||
type openFinding struct {
|
||||
f meshconditions.Finding
|
||||
module, ref string
|
||||
}
|
||||
|
||||
// setFinding writes a finding when it differs from the one written; the module and ref are the parts of its id.
|
||||
// setFinding writes a finding when it differs from the one held; the module and ref are the parts of its id.
|
||||
func (c *Config) setFinding(module, ref string, f meshconditions.Finding) {
|
||||
if c.Findings == nil {
|
||||
return
|
||||
@@ -97,17 +92,14 @@ func (c *Config) setFinding(module, ref string, f meshconditions.Finding) {
|
||||
key := views.FindingKey(f.Scope, f.ID, f.Kind)
|
||||
c.findMu.Lock()
|
||||
defer c.findMu.Unlock()
|
||||
if old, ok := c.open[key]; ok && old.f.Summary == f.Summary {
|
||||
return // what it says has not changed
|
||||
for _, old := range c.Findings.Held() {
|
||||
if views.FindingKey(old.Scope, old.ID, old.Kind) == key && old.Summary == f.Summary {
|
||||
return // what it says has not changed
|
||||
}
|
||||
}
|
||||
if err := c.Findings.Write(context.Background(), f); err != nil {
|
||||
c.logf("[mesh-config] the finding %s is not written: %v", key, err)
|
||||
return
|
||||
}
|
||||
if c.open == nil {
|
||||
c.open = map[string]openFinding{}
|
||||
}
|
||||
c.open[key] = openFinding{f: f, module: module, ref: ref}
|
||||
}
|
||||
|
||||
// clearFinding clears the findings of a kind and ref about a module, on whatever node but those in keep.
|
||||
@@ -117,30 +109,17 @@ func (c *Config) clearFinding(kind, module, ref string, keep ...string) {
|
||||
}
|
||||
c.findMu.Lock()
|
||||
defer c.findMu.Unlock()
|
||||
for k, o := range c.open {
|
||||
if o.f.Kind != kind || o.ref != ref || o.module != module ||
|
||||
(o.f.Subject.Machine != "" && slices.Contains(keep, o.f.Subject.Machine)) {
|
||||
for _, f := range c.Findings.Held() {
|
||||
if f.Kind != kind || f.ID != findingID(module, f.Subject.Machine, ref) ||
|
||||
(f.Subject.Machine != "" && slices.Contains(keep, f.Subject.Machine)) {
|
||||
continue
|
||||
}
|
||||
if err := c.Findings.Clear(context.Background(), o.f.Scope, o.f.ID, o.f.Kind, "the fault is gone"); err != nil {
|
||||
c.logf("[mesh-config] the finding %s is not cleared: %v", k, err)
|
||||
continue
|
||||
if err := c.Findings.Clear(context.Background(), f.Scope, f.ID, f.Kind, "the fault is gone"); err != nil {
|
||||
c.logf("[mesh-config] the finding %s is not cleared: %v", views.FindingKey(f.Scope, f.ID, f.Kind), err)
|
||||
}
|
||||
delete(c.open, k)
|
||||
}
|
||||
}
|
||||
|
||||
// FindingsObserved is the findings open now, for the writer's statement (views.WriterConfig.Observe).
|
||||
func (c *Config) FindingsObserved(context.Context) (views.Observed[meshconditions.Finding], error) {
|
||||
c.findMu.Lock()
|
||||
defer c.findMu.Unlock()
|
||||
var out views.Observed[meshconditions.Finding]
|
||||
for _, o := range c.open {
|
||||
out.Findings = append(out.Findings, o.f)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// retirementHeld is the finding of a retirement that waits seven days for nodes that still run a build reading the value.
|
||||
func retirementHeld(e Retiring, at time.Time) meshconditions.Finding {
|
||||
node := ""
|
||||
|
||||
@@ -121,9 +121,9 @@ func (runtimeAsks) Warranted(ask string) error {
|
||||
func main() {
|
||||
c := &Config{Store: runtimeStore{}, Logf: logf, Asks: runtimeAsks{}, Forge: toolForge{ask: stdio.Ask},
|
||||
Delivery: toolDelivery{ask: stdio.Ask}, Vault: toolVault{ask: stdio.Ask, recorder: recorder}}
|
||||
// The module's one writer (design 47 G §689, A-16): the renames' and retirements' findings and the views reader's go through it.
|
||||
w, err := views.NewStdioWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: Module, State: stdio.State(FindingsState), Observe: c.FindingsObserved,
|
||||
// The module's one held writer (design 47 G §689, A-16, A-29, A-32): the renames' and retirements' findings and the views reader's go through it.
|
||||
w, err := views.NewStdioHeldWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: Module, State: stdio.State(FindingsState),
|
||||
Kinds: []string{FindingRenameRefused, FindingWindowHeld, FindingRetireUnanswered, FindingRetireHeld}})
|
||||
if err != nil {
|
||||
logf("%v", err)
|
||||
|
||||
@@ -274,6 +274,8 @@ func TestAWindowHeldSevenDaysIsAFindingAndAHandCloseIsAHandAct(t *testing.T) {
|
||||
t.Error("a node holding no open window was dropped")
|
||||
}
|
||||
m.handActs = nil
|
||||
// A restart in between: the module holds no finding of its own, the writer holds it (design 47 G A-32, A-38).
|
||||
c = &Config{Store: c.Store, Now: c.Now, Logf: c.Logf, Delivery: c.Delivery, Findings: c.Findings}
|
||||
if _, err := c.RenameClose("player", "level", "novox", "novox is retired for good"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -443,6 +445,19 @@ func (m *memStore) Write(_ context.Context, f meshconditions.Finding) error {
|
||||
return m.Put(FindingsState, views.FindingKey(f.Scope, f.ID, f.Kind), f)
|
||||
}
|
||||
|
||||
// Held is what the writer holds: the findings in the module's state.
|
||||
func (m *memStore) Held() []meshconditions.Finding {
|
||||
var out []meshconditions.Finding
|
||||
for _, k := range m.keysOf(FindingsState) {
|
||||
e, _ := m.Get(FindingsState, k)
|
||||
var f meshconditions.Finding
|
||||
if e != nil && json.Unmarshal(e.Value, &f) == nil {
|
||||
out = append(out, f)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (m *memStore) Clear(_ context.Context, scope, id, kind, _ string) error {
|
||||
return m.Delete(FindingsState, views.FindingKey(scope, id, kind))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user