Skip to content

Commit 57f4ce1

Browse files
authored
Merge pull request #74 from mapx/update_bazel_build
Update bazel build module
2 parents 14c2af8 + 4bd04c1 commit 57f4ce1

File tree

9 files changed

+204
-291
lines changed

9 files changed

+204
-291
lines changed

BUILD

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
cc_library(
2-
name = "prometheus-cpp",
3-
srcs = ["lib/check_names.cc",
4-
"lib/counter.cc",
5-
"lib/gauge.cc",
6-
"lib/exposer.cc",
7-
"lib/handler.cc",
8-
"lib/handler.h",
9-
"lib/histogram.cc",
10-
"lib/registry.cc",
11-
"lib/text_serializer.cc",
12-
"lib/text_serializer.h",
13-
"lib/json_serializer.cc",
14-
"lib/json_serializer.h",
15-
"lib/serializer.h",
16-
"lib/protobuf_delimited_serializer.cc",
17-
"lib/protobuf_delimited_serializer.h",
18-
"lib/counter_builder.cc",
19-
"lib/gauge_builder.cc",
20-
"lib/histogram_builder.cc",
21-
],
22-
hdrs = glob([
23-
"include/prometheus/*.h",
24-
]),
2+
name = "prometheus_cpp",
3+
srcs = [
4+
"lib/check_names.cc",
5+
"lib/counter.cc",
6+
"lib/counter_builder.cc",
7+
"lib/exposer.cc",
8+
"lib/gauge.cc",
9+
"lib/gauge_builder.cc",
10+
"lib/handler.cc",
11+
"lib/handler.h",
12+
"lib/histogram.cc",
13+
"lib/histogram_builder.cc",
14+
"lib/json_serializer.cc",
15+
"lib/json_serializer.h",
16+
"lib/protobuf_delimited_serializer.cc",
17+
"lib/protobuf_delimited_serializer.h",
18+
"lib/registry.cc",
19+
"lib/serializer.h",
20+
"lib/text_serializer.cc",
21+
"lib/text_serializer.h",
22+
],
23+
hdrs = glob(
24+
["include/prometheus/*.h"],
25+
),
26+
linkstatic = 1,
2527
strip_include_prefix = "include",
2628
visibility = ["//visibility:public"],
27-
deps = ["@protobuf//:protobuf",
28-
"@prometheus_client_model//:prometheus_client_model",
29-
"@civetweb//:civetweb",
30-
],
31-
linkstatic = 1,
32-
copts = ["-I."],
29+
deps = [
30+
"@civetweb//:civetweb",
31+
"@com_google_protobuf//:protobuf",
32+
"@prometheus_client_model//:prometheus_client_model",
33+
],
3334
)

README.md

Lines changed: 32 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ other push/pull collections can be added as plugins.
1717
#include <string>
1818
#include <thread>
1919

20-
#include "lib/exposer.h"
21-
#include "lib/registry.h"
20+
#include <prometheus/exposer.h>
21+
#include <prometheus/registry.h>
2222

2323
int main(int argc, char** argv) {
2424
using namespace prometheus;
2525

2626
// create an http server running on port 8080
27-
auto exposer = Exposer{"127.0.0.1:8080"};
27+
Exposer exposer{"127.0.0.1:8080"};
2828

2929
// create a metrics registry with component=main labels applied to all its
3030
// metrics
@@ -97,107 +97,63 @@ make DESTDIR=`pwd`/deploy install
9797
### via Bazel
9898

9999
Install [bazel](https://www.bazel.io). Bazel makes it easy to add
100-
this repo to your project as a dependency. Unfortunately some of the
101-
direct and transitive dependencies do not provide bazel files. You need
102-
to add the following to your WORKSPACE:
103-
104-
```
105-
new_git_repository(
106-
name = "prometheus_client_model",
107-
remote = "https://github.com/prometheus/client_model.git",
108-
commit = "e2da43a",
109-
build_file_content = """
110-
cc_library(
111-
name = "prometheus_client_model",
112-
srcs = [
113-
"cpp/metrics.pb.cc",
114-
],
115-
hdrs = [
116-
"cpp/metrics.pb.h",
117-
],
118-
includes = [
119-
"cpp",
120-
],
121-
visibility = ["//visibility:public"],
122-
deps = ["@protobuf//:protobuf"],
123-
)
124-
""",
125-
)
100+
this repo to your project as a dependency. Just add the following
101+
to your `WORKSPACE`:
126102

103+
```python
127104
git_repository(
128-
name = "protobuf",
129-
remote = "https://github.com/google/protobuf.git",
130-
tag = "v3.0.0",
131-
)
132-
133-
new_git_repository(
134-
name = "civetweb",
135-
remote = "https://github.com/civetweb/civetweb.git",
136-
commit = "fbdee74",
137-
build_file_content = """
138-
cc_library(
139-
name = "civetweb",
140-
srcs = [
141-
"src/civetweb.c",
142-
"src/CivetServer.cpp",
143-
],
144-
hdrs = [
145-
"include/civetweb.h",
146-
"include/CivetServer.h",
147-
"src/md5.inl",
148-
"src/handle_form.inl",
149-
],
150-
includes = [
151-
"include",
152-
],
153-
copts = [
154-
"-DUSE_IPV6",
155-
"-DNDEBUG",
156-
"-DNO_CGI",
157-
"-DNO_CACHING",
158-
"-DNO_SSL",
159-
"-DNO_FILES",
160-
],
161-
visibility = ["//visibility:public"],
162-
)
163-
"""
105+
name = "prometheus_cpp",
106+
remote = https://github.com/jupp0r/prometheus-cpp.git",
164107
)
165108

166-
git_repository(
167-
name = "prometheus_cpp",
168-
remote = "https://github.com/jupp0r/prometheus-cpp.git",
169-
commit = "9c865b1c1a4234fa063e91225bb228111ee922ac",
170-
)
109+
load("@prometheus_cpp//:repositories.bzl", "prometheus_cpp_repositories")
110+
111+
prometheus_cpp_repositories()
171112
```
172113

173-
Then, you can reference this library in your own BUILD file, as
114+
Then, you can reference this library in your own `BUILD` file, as
174115
demonstrated with the sample server included in this repository:
175116

176-
```
117+
```python
177118
cc_binary(
178119
name = "sample_server",
179120
srcs = ["sample_server.cc"],
180-
deps = ["@prometheus_cpp//lib:prometheus-cpp"],
121+
deps = ["@prometheus_cpp//:prometheus_cpp"],
181122
)
182123
```
183124

125+
When you call `prometheus_cpp_repositories()` in your `WORKSPACE` file,
126+
you introduce the following dependencies to your project:
127+
128+
* `load_com_google_protobuf()` for Google protobuf
129+
* `load_prometheus_client_model()` for Prometheus data model artifacts
130+
* `load_civetweb()` for Civetweb
131+
* `load_com_google_googletest()` for Google gtest
132+
* `load_com_google_googlebenchmark()` for Googlebenchmark
133+
134+
You may load them individually and replace some of them with your custom
135+
dependency version.
136+
137+
The list of dependencies is also available from file `repositories.bzl`.
138+
139+
184140
## Contributing
185141

186142
You can check out this repo and build the library using
187143
``` bash
188-
bazel build //:prometheus-cpp
144+
bazel build //:prometheus_cpp
189145
```
190146

191147
Run the unit tests using
192148
```
193-
bazel test //tests:prometheus_test
149+
bazel test //tests:prometheus-test
194150
```
195151

196152
There is also an integration test that
197153
uses [telegraf](https://github.com/influxdata/telegraf) to scrape a
198154
sample server. With telegraf installed, it can be run using
199155
```
200-
bazel test //tests/integration:scrape_test
156+
bazel test //tests/integration:scrape-test
201157
```
202158

203159
## Benchmarks

WORKSPACE

Lines changed: 3 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,5 @@
1-
new_git_repository(
2-
name = "googletest",
3-
remote = "https://github.com/google/googletest.git",
4-
tag = "release-1.8.0",
5-
build_file_content = """
6-
cc_library(
7-
name = "gmock",
8-
srcs = [
9-
"googletest/src/gtest-all.cc",
10-
"googlemock/src/gmock-all.cc",
11-
],
12-
hdrs = glob([
13-
"googletest/**/*.h",
14-
"googlemock/**/*.h",
15-
"googletest/src/*.cc",
16-
"googlemock/src/*.cc",
17-
]),
18-
includes = [
19-
"googlemock",
20-
"googletest",
21-
"googletest/include",
22-
"googlemock/include",
23-
],
24-
linkopts = ["-pthread"],
25-
visibility = ["//visibility:public"],
26-
)
1+
workspace(name = "prometheus_cpp")
272

28-
cc_library(
29-
name = "main",
30-
srcs = ["googlemock/src/gmock_main.cc"],
31-
linkopts = ["-pthread"],
32-
visibility = ["//visibility:public"],
33-
deps = [":gmock"],
34-
)
3+
load(":repositories.bzl", "prometheus_cpp_repositories")
354

36-
""",
37-
)
38-
39-
new_git_repository(
40-
name = "prometheus_client_model",
41-
remote = "https://github.com/prometheus/client_model.git",
42-
commit = "e2da43a",
43-
build_file_content = """
44-
load("@protobuf//:protobuf.bzl", "cc_proto_library")
45-
cc_proto_library(
46-
name = "prometheus_client_model",
47-
srcs = ["metrics.proto"],
48-
protoc = "@protobuf//:protoc",
49-
default_runtime = "@protobuf//:protobuf",
50-
visibility = ["//visibility:public"],
51-
)
52-
""",
53-
)
54-
55-
git_repository(
56-
name = "protobuf",
57-
remote = "https://github.com/google/protobuf.git",
58-
tag = "v3.2.0",
59-
)
60-
61-
new_git_repository(
62-
name = "civetweb",
63-
remote = "https://github.com/civetweb/civetweb.git",
64-
commit = "fbdee74",
65-
build_file_content = """
66-
cc_library(
67-
name = "civetweb",
68-
srcs = [
69-
"src/civetweb.c",
70-
"src/CivetServer.cpp",
71-
],
72-
hdrs = [
73-
"include/civetweb.h",
74-
"include/CivetServer.h",
75-
],
76-
textual_hdrs = [
77-
"src/md5.inl",
78-
"src/handle_form.inl",
79-
],
80-
includes = [
81-
"include",
82-
],
83-
copts = [
84-
"-DUSE_IPV6",
85-
"-DNDEBUG",
86-
"-DNO_CGI",
87-
"-DNO_CACHING",
88-
"-DNO_SSL",
89-
"-DNO_FILES",
90-
],
91-
visibility = ["//visibility:public"],
92-
)
93-
"""
94-
)
95-
96-
new_git_repository(
97-
name = "googlebenchmark",
98-
remote = "https://github.com/google/benchmark.git",
99-
commit = "57a22c69b382b3f010ec4042c9574ea3fd8dcbb4",
100-
build_file_content = """
101-
cc_library(
102-
name = "googlebenchmark",
103-
srcs = glob(["src/*.cc"],
104-
exclude = ["src/re_posix.cc", "src/gnuregex.cc"]),
105-
hdrs = glob(["src/*.h", "include/benchmark/*.h"],
106-
exclude = ["src/re_posix.h", "src/gnuregex.h"]),
107-
includes = [
108-
"include",
109-
],
110-
visibility = ["//visibility:public"],
111-
copts = [
112-
"-DHAVE_STD_REGEX"
113-
],
114-
)
115-
"""
116-
)
5+
prometheus_cpp_repositories()

0 commit comments

Comments
 (0)