Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.24.0
toolchain go1.24.6

require (
github.com/go-kit/kit v0.13.0
github.com/go-logfmt/logfmt v0.6.0
github.com/gogo/googleapis v1.4.1
github.com/gogo/protobuf v1.3.2
Expand All @@ -32,7 +31,6 @@ require (
github.com/KimMachineGun/automemlimit v0.7.4
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b
github.com/felixge/httpsnoop v1.0.4
github.com/go-kit/log v0.2.1
github.com/gogo/status v1.1.1
github.com/grafana/loki/pkg/push v0.0.0-20250903135404-0b2d0b070e96
github.com/jpillora/backoff v1.0.0
Expand All @@ -41,7 +39,6 @@ require (
github.com/quasilyte/go-ruleguard/dsl v0.3.22
github.com/spf13/afero v1.14.0
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b
gopkg.in/yaml.v3 v3.0.1
kernel.org/pub/linux/libs/security/libcap/cap v1.2.76
)

Expand Down Expand Up @@ -76,6 +73,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
kernel.org/pub/linux/libs/security/libcap/psx v1.2.76 // indirect
)

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ github.com/dennwc/varint v1.0.0/go.mod h1:hnItb35rvZvJrbTALZtY/iQfDs48JKRG1RPpgz
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU=
github.com/go-kit/kit v0.13.0/go.mod h1:phqEHMMUbyrCFCTgH48JueqrM3md2HcAZ8N3XE4FKDg=
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
Expand Down
28 changes: 5 additions & 23 deletions internal/adhoc/adhoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,34 +464,16 @@ func sleepCtx(ctx context.Context, d time.Duration) error {
return err
}

// jsonLogger implements the log.Logger interface.
type jsonLogger struct {
entries []map[string]string
}

// Log takes key-value pairs and logs them.
func (l *jsonLogger) Log(keyvals ...interface{}) error {
m := make(map[string]string)
if len(keyvals)%2 != 0 {
return fmt.Errorf("expected even number of keyvals, got %d", len(keyvals))
}
for i := 0; i < len(keyvals); i += 2 {
k := fmt.Sprintf("%v", keyvals[i])
v := fmt.Sprintf("%v", keyvals[i+1])
m[k] = v
}
l.entries = append(l.entries, m)
return nil
}

// Run runs the specified prober once and captures the results using
// jsonLogger.
func (r *runner) Run(ctx context.Context, tenantId model.GlobalID, publisher pusher.Publisher) {
r.logger.Info().Msg("running ad-hoc check")

registry := prometheus.NewRegistry()

logger := &jsonLogger{}
// Create a logger that captures entries for later use
var logBuf bytes.Buffer
zlogger := zerolog.New(&logBuf)

// TODO(mem): decide what to do with these metrics.
successGauge := prometheus.NewGauge(prometheus.GaugeOpts{
Expand All @@ -513,7 +495,7 @@ func (r *runner) Run(ctx context.Context, tenantId model.GlobalID, publisher pus
rCtx, cancel := context.WithTimeout(ctx, r.timeout)
defer cancel()

success, duration := r.prober.Probe(rCtx, r.target, registry, logger)
success, duration := r.prober.Probe(rCtx, r.target, registry, zlogger)

if success {
successGauge.Set(1)
Expand All @@ -538,7 +520,7 @@ func (r *runner) Run(ctx context.Context, tenantId model.GlobalID, publisher pus
Str("target", r.target).
Str("probe", r.probe).
Str("check_name", r.prober.Name()).
Interface("logs", logger.entries).
Str("logs", logBuf.String()).
Interface("timeseries", mfs).
Msg("ad-hoc check done")

Expand Down
5 changes: 2 additions & 3 deletions internal/adhoc/adhoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/grafana/synthetic-monitoring-agent/internal/feature"
"github.com/grafana/synthetic-monitoring-agent/internal/k6runner"
"github.com/grafana/synthetic-monitoring-agent/internal/prober"
"github.com/grafana/synthetic-monitoring-agent/internal/prober/logger"
"github.com/grafana/synthetic-monitoring-agent/internal/pusher"
"github.com/grafana/synthetic-monitoring-agent/internal/testhelper"
sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring"
Expand Down Expand Up @@ -341,14 +340,14 @@ func (p *testProber) Name() string {
return "test"
}

func (p *testProber) Probe(ctx context.Context, target string, registry *prometheus.Registry, logger logger.Logger) (bool, float64) {
func (p *testProber) Probe(ctx context.Context, target string, registry *prometheus.Registry, zlogger zerolog.Logger) (bool, float64) {
p.logger.Info().Str("func", "Probe").Caller(0).Send()
g := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "test",
})
g.Set(1)
registry.MustRegister(g)
_ = logger.Log("msg", "test")
zlogger.Info().Str("msg", "test").Send()
return true, 1
}

Expand Down
3 changes: 1 addition & 2 deletions internal/checks/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/grafana/synthetic-monitoring-agent/internal/k6runner"
"github.com/grafana/synthetic-monitoring-agent/internal/model"
"github.com/grafana/synthetic-monitoring-agent/internal/prober"
"github.com/grafana/synthetic-monitoring-agent/internal/prober/logger"
"github.com/grafana/synthetic-monitoring-agent/internal/pusher"
"github.com/grafana/synthetic-monitoring-agent/internal/scraper"
"github.com/grafana/synthetic-monitoring-agent/internal/telemetry"
Expand Down Expand Up @@ -443,7 +442,7 @@ func (testProber) Name() string {
return "test-prober"
}

func (testProber) Probe(ctx context.Context, target string, registry *prometheus.Registry, logger logger.Logger) (bool, float64) {
func (testProber) Probe(ctx context.Context, target string, registry *prometheus.Registry, zlogger zerolog.Logger) (bool, float64) {
return false, 0
}

Expand Down
Loading
Loading