Repository navigation
Expand file tree
/
Copy pathBUILD.bazel
More file actions
139 lines (130 loc) · 5.19 KB
/
Copy pathBUILD.bazel
File metadata and controls
139 lines (130 loc) · 5.19 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "monitoring_lib",
srcs = ["main.go"],
importpath = "github.com/sourcegraph/sourcegraph/monitoring",
visibility = ["//visibility:private"],
deps = [
"//monitoring/command",
"@com_github_sourcegraph_log//:log",
"@com_github_urfave_cli_v2//:cli",
],
)
go_binary(
name = "monitoring",
embed = [":monitoring_lib"],
visibility = ["//visibility:public"],
)
genrule(
name = "generate_config_zip",
srcs = [],
outs = ["monitoring.zip"],
cmd = """
$(location //monitoring:monitoring) generate \
--all.dir monitoring && \
zip -r $@ monitoring
""",
tools = ["//monitoring"],
visibility = ["//docker-images/grafana:__pkg__"],
)
genrule(
name = "generate_grafana_config_tar",
srcs = [],
outs = ["monitoring.tar"],
cmd = """
$(location //monitoring:monitoring) generate \
--all.dir monitoring && \
mkdir -p usr/share/grafana/public/dashboards/ && \
mv monitoring/grafana/home.json usr/share/grafana/public/dashboards/ && \
mkdir -p sg_config_grafana/provisioning/dashboards/sourcegraph/ && \
mv monitoring/grafana/* sg_config_grafana/provisioning/dashboards/sourcegraph/ &&\
tar -cf $@ usr/share/grafana/public/dashboards/ sg_config_grafana/provisioning/dashboards/sourcegraph/
""",
tools = ["//monitoring"],
visibility = ["//visibility:public"],
)
# Bazel expects all outputs to be explicitly defined. Therefore we have
# to manually list them here. This so we can use this target as inputs to a
# pkg_tar rule. Using the zip variant from above would not work, as we
# would have to write a rule that unzips it and ... we'll circle back to
# the issue of having non-deterministic outputs for bazel to work with.
#
# To avoid accidentally missing one silently, which would be very hard
# to debug, there is a test target :generate_config_test below that
# runs the monitoring tool once again to ensure that all generated files are present in the output below, acting as failsafe to detect any deviation.
genrule(
name = "generate_config",
srcs = [],
outs = [
"outputs/docs/alerts.md",
"outputs/docs/dashboards.md",
"outputs/grafana/codeintel-autoindexing.json",
"outputs/grafana/codeintel-codenav.json",
"outputs/grafana/codeintel-policies.json",
"outputs/grafana/codeintel-ranking.json",
"outputs/grafana/codeintel-uploads.json",
"outputs/grafana/containers.json",
"outputs/grafana/embeddings.json",
"outputs/grafana/executor.json",
"outputs/grafana/frontend.json",
"outputs/grafana/github-proxy.json",
"outputs/grafana/gitserver.json",
"outputs/grafana/home.json",
"outputs/grafana/otel-collector.json",
"outputs/grafana/postgres.json",
"outputs/grafana/precise-code-intel-worker.json",
"outputs/grafana/prometheus.json",
"outputs/grafana/redis.json",
"outputs/grafana/repo-updater.json",
"outputs/grafana/searcher.json",
"outputs/grafana/symbols.json",
"outputs/grafana/syntect-server.json",
"outputs/grafana/telemetry.json",
"outputs/grafana/worker.json",
"outputs/grafana/zoekt.json",
"outputs/prometheus/codeintel_autoindexing_alert_rules.yml",
"outputs/prometheus/codeintel_codenav_alert_rules.yml",
"outputs/prometheus/codeintel_policies_alert_rules.yml",
"outputs/prometheus/codeintel_ranking_alert_rules.yml",
"outputs/prometheus/codeintel_uploads_alert_rules.yml",
"outputs/prometheus/containers_alert_rules.yml",
"outputs/prometheus/embeddings_alert_rules.yml",
"outputs/prometheus/executor_alert_rules.yml",
"outputs/prometheus/frontend_alert_rules.yml",
"outputs/prometheus/github_proxy_alert_rules.yml",
"outputs/prometheus/gitserver_alert_rules.yml",
"outputs/prometheus/otel_collector_alert_rules.yml",
"outputs/prometheus/postgres_alert_rules.yml",
"outputs/prometheus/precise_code_intel_worker_alert_rules.yml",
"outputs/prometheus/prometheus_alert_rules.yml",
"outputs/prometheus/redis_alert_rules.yml",
"outputs/prometheus/repo_updater_alert_rules.yml",
"outputs/prometheus/searcher_alert_rules.yml",
"outputs/prometheus/src_custom_rules.yml",
"outputs/prometheus/symbols_alert_rules.yml",
"outputs/prometheus/syntect_server_alert_rules.yml",
"outputs/prometheus/telemetry_alert_rules.yml",
"outputs/prometheus/worker_alert_rules.yml",
"outputs/prometheus/zoekt_alert_rules.yml",
],
cmd = """
mkdir -p $(@D)/outputs
$(location //monitoring:monitoring) generate \
--all.dir $(@D)/outputs/
""",
tools = ["//monitoring"],
visibility = ["//visibility:public"],
)
sh_test(
name = "generate_config_test",
size = "small",
srcs = ["generate_config_test.sh"],
args = [
"$(location :monitoring)",
"$(locations :generate_config)",
],
data = [
":generate_config",
":monitoring",
],
)