feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
95
internal/checkexec/exec.go
Обычный файл
95
internal/checkexec/exec.go
Обычный файл
@@ -0,0 +1,95 @@
|
||||
// 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 (
|
||||
"rsgit.ru/rsmon/rsmon/app/models"
|
||||
"rsgit.ru/rsmon/rsmon/checks/calls"
|
||||
"rsgit.ru/rsmon/rsmon/checks/cbssl"
|
||||
"rsgit.ru/rsmon/rsmon/checks/cdns"
|
||||
"rsgit.ru/rsmon/rsmon/checks/cftp"
|
||||
"rsgit.ru/rsmon/rsmon/checks/chttp"
|
||||
"rsgit.ru/rsmon/rsmon/checks/cping"
|
||||
"rsgit.ru/rsmon/rsmon/checks/cssh"
|
||||
"rsgit.ru/rsmon/rsmon/checks/cssl"
|
||||
"rsgit.ru/rsmon/rsmon/checks/ctcp"
|
||||
"rsgit.ru/rsmon/rsmon/checks/cudp"
|
||||
"rsgit.ru/rsmon/rsmon/checks/cwhois"
|
||||
"rsgit.ru/rsmon/rsmon/checks/llmhttp"
|
||||
"rsgit.ru/rsmon/rsmon/internal/checkresult"
|
||||
"rsgit.ru/rsmon/rsmon/internal/wire"
|
||||
)
|
||||
|
||||
// ExecutedCheck is the DB-free result of a distributed check execution.
|
||||
type ExecutedCheck struct {
|
||||
Result checkresult.CheckResult
|
||||
Metrics []wire.MetricPoint
|
||||
}
|
||||
|
||||
// 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
|
||||
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,
|
||||
}},
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user