Skip to content

Commit

Permalink
tmp: deduplicate metrics config validation [1/2]
Browse files Browse the repository at this point in the history
Patch for "agent: Make metrics fetching generic".
  • Loading branch information
sharnoff committed May 27, 2024
1 parent 031cc2d commit 86cb9f4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,13 @@ func (c *Config) validate() error {
}
erc.Whenf(ec, c.DumpState != nil && c.DumpState.Port == 0, zeroTmpl, ".dumpState.port")
erc.Whenf(ec, c.DumpState != nil && c.DumpState.TimeoutSeconds == 0, zeroTmpl, ".dumpState.timeoutSeconds")
erc.Whenf(ec, c.Metrics.System.Port == 0, zeroTmpl, ".metrics.system.port")
erc.Whenf(ec, c.Metrics.System.RequestTimeoutSeconds == 0, zeroTmpl, ".metrics.system.requestTimeoutSeconds")
erc.Whenf(ec, c.Metrics.System.SecondsBetweenRequests == 0, zeroTmpl, ".metrics.system.secondsBetweenRequests")

validateMetricsConfig := func(cfg MetricsSourceConfig, key string) {
erc.Whenf(ec, cfg.Port == 0, zeroTmpl, fmt.Sprintf(".metrics.%s.port", key))
erc.Whenf(ec, cfg.RequestTimeoutSeconds == 0, zeroTmpl, fmt.Sprintf(".metrics.%s.requestTimeoutSeconds", key))
erc.Whenf(ec, cfg.SecondsBetweenRequests == 0, zeroTmpl, fmt.Sprintf(".metrics.%s.secondsBetweenRequests", key))
}
validateMetricsConfig(c.Metrics.System, "system")
erc.Whenf(ec, c.Metrics.LFC.Port == 0, zeroTmpl, ".metrics.lfc.port")
erc.Whenf(ec, c.Metrics.LFC.RequestTimeoutSeconds == 0, zeroTmpl, ".metrics.lfc.requestTimeoutSeconds")
erc.Whenf(ec, c.Metrics.LFC.SecondsBetweenRequests == 0, zeroTmpl, ".metrics.lfc.secondsBetweenRequests")
Expand Down

0 comments on commit 86cb9f4

Please sign in to comment.