Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/tools/smoke/main.go
4094 views
1
package main
2
3
import (
4
"context"
5
"flag"
6
"os"
7
"time"
8
9
"github.com/go-kit/log/level"
10
"github.com/grafana/agent/pkg/server"
11
smoke "github.com/grafana/agent/tools/smoke/internal"
12
"github.com/weaveworks/common/logging"
13
)
14
15
func main() {
16
var (
17
cfg smoke.Config
18
logLevel logging.Level
19
logFormat logging.Format
20
withTimeout time.Duration
21
)
22
23
cfg.RegisterFlags(flag.CommandLine)
24
logLevel.RegisterFlags(flag.CommandLine)
25
logFormat.RegisterFlags(flag.CommandLine)
26
flag.DurationVar(&withTimeout, "duration", time.Duration(0), "test duration")
27
flag.Parse()
28
29
logger := server.NewLoggerFromLevel(logLevel, logFormat)
30
31
ctx := context.Background()
32
if withTimeout > 0 {
33
var cancel context.CancelFunc
34
ctx, cancel = context.WithTimeout(ctx, withTimeout)
35
defer cancel()
36
level.Debug(logger).Log("msg", "running with duration", "duration", withTimeout.String())
37
}
38
39
level.Info(logger).Log("msg", "starting smoke test")
40
smokeTest, err := smoke.New(logger, cfg)
41
if err != nil {
42
level.Error(logger).Log("msg", "error constructing smoke test", "err", err)
43
os.Exit(1)
44
}
45
if err := smokeTest.Run(ctx); err != nil {
46
level.Error(logger).Log("msg", "smoke test run failure", "err", err)
47
os.Exit(1)
48
}
49
}
50
51