Files
worker/internal/checkexec/exec.go
Gleb Tv e987f24903
Все проверки выполнены успешно
CI / test (push) Successful in 2m32s
Docker / Build and publish worker image (push) Successful in 18m17s
fix(worker): harden control-plane lifecycle
- reconnect safely after token rotation and retry leased results
- reject malformed tasks and remove production cluster debug mutation
- validate environment files and require immutable container images

BREAKING CHANGE: Docker install, deploy, and Compose now require an
immutable repository@sha256 image reference.
2026-07-19 23:11:43 +03:00

109 строки
3.8 KiB
Go

// Package checkexec provides DB-free check execution for distributed workers.
// It executes checks without saving results to database or InfluxDB,
// allowing remote workers to report results via API.
package checkexec
import (
"rocketgit.ru/rsmon/worker/app/models"
"rocketgit.ru/rsmon/worker/checks/calls"
"rocketgit.ru/rsmon/worker/checks/cbssl"
"rocketgit.ru/rsmon/worker/checks/cdns"
"rocketgit.ru/rsmon/worker/checks/cftp"
"rocketgit.ru/rsmon/worker/checks/chttp"
"rocketgit.ru/rsmon/worker/checks/cping"
"rocketgit.ru/rsmon/worker/checks/cssh"
"rocketgit.ru/rsmon/worker/checks/cssl"
"rocketgit.ru/rsmon/worker/checks/ctcp"
"rocketgit.ru/rsmon/worker/checks/cudp"
"rocketgit.ru/rsmon/worker/checks/cwhois"
"rocketgit.ru/rsmon/worker/checks/llmhttp"
"rocketgit.ru/rsmon/worker/internal/checkresult"
"rocketgit.ru/rsmon/worker/internal/wire"
)
// ExecutedCheck is the DB-free result of a distributed check execution.
type ExecutedCheck struct {
Result checkresult.CheckResult
Metrics []wire.MetricPoint
}
// SupportsKind reports whether Execute has a local executor for kind.
func SupportsKind(kind string) bool {
switch kind {
case "http", "ssl", "ssh", "ftp", "dns", "whois", "bssl", "llm", "llm-http", "ping", "tcp", "udp":
return true
default:
return false
}
}
// Execute runs checks without saving to DB or InfluxDB.
// Results are returned for reporting via API to the control plane.
// This is designed for distributed workers that have no direct DB access.
func Execute(m *models.Monitor, checks []models.Check) []ExecutedCheck {
results := make([]ExecutedCheck, 0, len(checks))
for i := range checks {
c := &checks[i]
c.Monitor = m
if !SupportsKind(c.Kind) {
continue
}
switch c.Kind {
case "http":
r := chttp.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "ssl":
r := cssl.Perform(c)
results = append(results, executed(&r.CheckResult))
case "ssh":
r := cssh.Perform(c)
results = append(results, executed(&r.CheckResult))
case "ftp":
r := cftp.Perform(c)
results = append(results, executed(&r.CheckResult))
case "dns":
r := cdns.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "whois":
r := cwhois.Perform(c)
results = append(results, executed(&r.CheckResult))
case "bssl":
r := cbssl.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "llm":
r := calls.Perform(c)
results = append(results, executed(&r.CheckResult))
case "llm-http":
r := llmhttp.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "ping":
r := cping.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "tcp":
r := ctcp.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
case "udp":
r := cudp.Perform(c)
results = append(results, executedWithMetric(c, r.CheckResult, r.InfluxTags(*c), r.InfluxFields()))
}
// Note: "rkn" checks are intentionally omitted as they are Russia-specific
// regulatory checks that should not run on distributed workers.
}
return results
}
func executed(result *checkresult.CheckResult) ExecutedCheck {
return ExecutedCheck{Result: *result}
}
func executedWithMetric(c *models.Check, result checkresult.CheckResult, tags map[string]string, fields map[string]interface{}) ExecutedCheck { //nolint:gocritic,lll // helper keeps typed check results close to execution
return ExecutedCheck{
Result: result,
Metrics: []wire.MetricPoint{{
Metric: c.MetricName(),
Tags: tags,
Fields: fields,
}},
}
}