fix(agent): reset per-service warnings after a successful build check (#7)
This commit is contained in:
@@ -62,7 +62,7 @@ type Collector struct {
|
||||
|
||||
mu sync.Mutex
|
||||
cache map[string]buildEntry // by Compose project
|
||||
warned map[string]bool // projects whose check failure was logged
|
||||
warned map[string]bool // logged warnings: "<project>" (check failed) and "<project>/<service>" (service not in config)
|
||||
}
|
||||
|
||||
// buildEntry is the cached outcome of a build check. It is valid as long as
|
||||
@@ -313,15 +313,22 @@ func (c *Collector) builtServices(ctx context.Context, project string, l stackLa
|
||||
built, err := c.check.BuiltServices(ctx, project, l.workingDir, l.configFiles, l.envFile)
|
||||
c.cache[project] = buildEntry{key: key, built: built, err: err, at: c.now()}
|
||||
if err == nil {
|
||||
delete(c.warned, project)
|
||||
// Forget the project's warnings so they are logged again if the
|
||||
// problem returns. Project names cannot contain "/".
|
||||
for k := range c.warned {
|
||||
if k == project || strings.HasPrefix(k, project+"/") {
|
||||
delete(c.warned, k)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.warnOnceLocked(project, "compose_build_check_failed", "project", project, "error", err)
|
||||
}
|
||||
return built
|
||||
}
|
||||
|
||||
// warnOnce logs msg the first time it is called for key (until the next
|
||||
// successful check of the project resets it).
|
||||
// warnOnce logs msg the first time it is called for key. key is a project
|
||||
// name (its build check failed) or "<project>/<service>" (the service is not
|
||||
// in the project's config); a successful check of the project forgets both.
|
||||
func (c *Collector) warnOnce(key, msg string, args ...any) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user