/
agent.go
81 lines (65 loc) · 2.07 KB
/
agent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package testservers
import (
"fmt"
"os"
"os/exec"
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/config"
envstruct "code.cloudfoundry.org/go-envstruct"
"code.cloudfoundry.org/loggregator-agent-release/src/cmd/loggregator-agent/app"
"code.cloudfoundry.org/loggregator-agent-release/src/internal/testhelper"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
func BuildAgentConfig(dopplerURI string, dopplerGRPCPort int, testCerts *testhelper.TestCerts) app.Config {
return app.Config{
Index: jobIndex,
Job: jobName,
Zone: availabilityZone,
Tags: map[string]string{
"auto-tag-1": "auto-tag-value-1",
"auto-tag-2": "auto-tag-value-2",
},
Deployment: "deployment",
RouterAddr: fmt.Sprintf("%s:%d", dopplerURI, dopplerGRPCPort),
RouterAddrWithAZ: fmt.Sprintf("%s.%s:%d", availabilityZone, dopplerURI, dopplerGRPCPort),
GRPC: app.GRPC{
CertFile: testCerts.Cert("metron"),
KeyFile: testCerts.Key("metron"),
CAFile: testCerts.CA(),
},
MetricsServer: config.MetricsServer{
CertFile: testCerts.Cert("metron"),
KeyFile: testCerts.Key("metron"),
CAFile: testCerts.CA(),
},
MetricBatchIntervalMilliseconds: 5000,
}
}
type AgentPorts struct {
GRPC int
UDP int
Metrics int
}
func StartAgent(conf app.Config) (cleanup func(), mp AgentPorts) {
By("making sure agent was built")
agentPath := os.Getenv("AGENT_BUILD_PATH")
Expect(agentPath).ToNot(BeEmpty())
By("starting agent")
agentCommand := exec.Command(agentPath)
agentCommand.Env = envstruct.ToEnv(&conf)
agentSession, err := gexec.Start(
agentCommand,
gexec.NewPrefixedWriter(color("o", "agent", green, magenta), GinkgoWriter),
gexec.NewPrefixedWriter(color("e", "agent", red, magenta), GinkgoWriter),
)
Expect(err).ToNot(HaveOccurred())
By("waiting for agent to listen")
mp.Metrics = waitForPortBinding("metrics", agentSession.Err)
mp.GRPC = waitForPortBinding("grpc", agentSession.Err)
mp.UDP = waitForPortBinding("udp", agentSession.Err)
cleanup = func() {
agentSession.Kill().Wait()
}
return cleanup, mp
}