-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathtrace_agent.py
104 lines (88 loc) · 3.22 KB
/
trace_agent.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import sys
from invoke import task
from tasks.build_tags import add_fips_tags, filter_incompatible_tags, get_build_tags, get_default_build_tags
from tasks.flavor import AgentFlavor
from tasks.gointegrationtest import TRACE_AGENT_IT_CONF, containerized_integration_tests
from tasks.libs.common.utils import REPO_PATH, bin_name, get_build_flags
from tasks.windows_resources import build_messagetable, build_rc, versioninfo_vars
BIN_PATH = os.path.join(".", "bin", "trace-agent")
@task
def build(
ctx,
rebuild=False,
race=False,
build_include=None,
build_exclude=None,
flavor=AgentFlavor.base.name,
install_path=None,
major_version='7',
go_mod="readonly",
):
"""
Build the trace agent.
"""
flavor = AgentFlavor[flavor]
if flavor.is_ot():
flavor = AgentFlavor.base
fips_mode = flavor.is_fips()
ldflags, gcflags, env = get_build_flags(
ctx,
install_path=install_path,
major_version=major_version,
)
# generate windows resources
if sys.platform == 'win32':
build_messagetable(ctx)
vars = versioninfo_vars(ctx, major_version=major_version)
build_rc(
ctx,
"cmd/trace-agent/windows/resources/trace-agent.rc",
vars=vars,
out="cmd/trace-agent/rsrc.syso",
)
build_include = (
get_default_build_tags(
build="trace-agent",
flavor=flavor,
) # TODO/FIXME: Arch not passed to preserve build tags. Should this be fixed?
if build_include is None
else filter_incompatible_tags(build_include.split(","))
)
build_exclude = [] if build_exclude is None else build_exclude.split(",")
build_tags = get_build_tags(build_include, build_exclude)
build_tags = add_fips_tags(build_tags, fips_mode)
race_opt = "-race" if race else ""
build_type = "-a" if rebuild else ""
go_build_tags = " ".join(build_tags)
agent_bin = os.path.join(BIN_PATH, bin_name("trace-agent"))
cmd = f"go build -mod={go_mod} {race_opt} {build_type} -tags \"{go_build_tags}\" "
cmd += f"-o {agent_bin} -gcflags=\"{gcflags}\" -ldflags=\"{ldflags}\" {REPO_PATH}/cmd/trace-agent"
# go generate only works if you are in the module the target file is in, so we
# need to move into the pkg/trace module.
with ctx.cd("./pkg/trace"):
ctx.run(f"go generate -mod={go_mod} {REPO_PATH}/pkg/trace/info", env=env)
ctx.run(cmd, env=env)
@task
def integration_tests(ctx, race=False, go_mod="readonly", timeout="10m"):
"""
Run integration tests for trace agent
"""
containerized_integration_tests(
ctx,
TRACE_AGENT_IT_CONF,
race=race,
remote_docker=False,
go_mod=go_mod,
timeout=timeout,
)
@task
def benchmarks(ctx, bench, output="./trace-agent.benchmarks.out"):
"""
Runs the benchmarks. Use "--bench=X" to specify benchmarks to run. Use the "--output=X" argument to specify where to output results.
"""
if not bench:
print("Argument --bench=<bench_regex> is required.")
return
with ctx.cd("./pkg/trace"):
ctx.run(f"go test -tags=test -run=XXX -bench \"{bench}\" -benchmem -count 1 -benchtime 2s ./... | tee {output}")