Skip to content

Commit

Permalink
Update bazel version and dependencies (#22)
Browse files Browse the repository at this point in the history
* Update bazel version and dependencies
- Update bazel to 3.1.0
- Upgrade bazel-based deps to work with 3.1.0
- Upgrade jar deps to newest version to avoid conflict with bazel-based deps
- Update tests, removing deprecated methods and
- Remove unneeded deps

* make test server names private

* Use official grpc-java rules for building grpc libs for java
Also removes now unneeded third party grpc rules

* Use grpc-java targets as deps rather than maven artifacts
  • Loading branch information
afsluit authored Jun 1, 2020
1 parent f7c056c commit f30daa5
Show file tree
Hide file tree
Showing 20 changed files with 1,117 additions and 319 deletions.
3 changes: 1 addition & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test --legacy_bazel_java_test
test --test_output=errors
test --test_output=errors
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ bazel-*
project.iml
output
*.swp
.ijwb
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ addons:
before_install:
- sudo apt-get purge openjdk-9*
- sudo apt-get purge oracle-java9*
- wget 'https://github.com/bazelbuild/bazel/releases/download/0.20.0/bazel_0.20.0-linux-x86_64.deb'
- chmod +x bazel_0.20.0-linux-x86_64.deb
- sudo dpkg -i bazel_0.20.0-linux-x86_64.deb
- wget 'https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel_3.1.0-linux-x86_64.deb'
- chmod +x bazel_3.1.0-linux-x86_64.deb
- sudo dpkg -i bazel_3.1.0-linux-x86_64.deb

script:
- bazel test --incompatible_remove_native_http_archive=false //src/...
- bazel test //src/...
Empty file added BUILD
Empty file.
82 changes: 35 additions & 47 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,67 +1,55 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "org_pubref_rules_protobuf",
strip_prefix = "rules_protobuf-0.8.1",
urls = ["https://github.com/pubref/rules_protobuf/archive/v0.8.1.zip"],
name = "io_grpc_grpc_java",
sha256 = "446ad7a2e85bbd05406dbf95232c7c49ed90de83b3b60cb2048b0c4c9f254d29",
strip_prefix = "grpc-java-1.29.0",
url = "https://github.com/grpc/grpc-java/archive/v1.29.0.zip",
)

load("@org_pubref_rules_protobuf//java:rules.bzl", "java_proto_repositories")
load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS")
load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS")

java_proto_repositories()
RULES_JVM_EXTERNAL_TAG = "3.0"

maven_jar(
name = "io_grpc_grpc_benchmarks",
artifact = "io.grpc:grpc-benchmarks:1.6.1",
)
RULES_JVM_EXTERNAL_SHA = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a"

maven_jar(
name = "io_grpc_grpc_okhttp",
artifact = "io.grpc:grpc-okhttp:1.6.1",
http_archive(
name = "rules_jvm_external",
sha256 = RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

maven_jar(
name = "grpc_testing_artifact",
artifact = "io.grpc:grpc-testing:1.4.0",
)
load("@rules_jvm_external//:defs.bzl", "maven_install")
load("//:repositories.bzl", "MAVEN_ARTIFACTS")

maven_jar(
name = "guava_artifact",
artifact = "com.google.guava:guava:21.0",
maven_install(
artifacts = MAVEN_ARTIFACTS + IO_GRPC_GRPC_JAVA_ARTIFACTS,
generate_compat_repositories = True,
maven_install_json = "//:maven_install.json",
override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS,
repositories = [
"https://jcenter.bintray.com/",
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
)

maven_jar(
name = "junit_artifact",
artifact = "junit:junit:4.10",
)
load("@maven//:defs.bzl", "pinned_maven_install")

maven_jar(
name = "netty_artifact",
artifact = "io.netty:netty-all:4.1.13.Final",
)
pinned_maven_install()

maven_jar(
name = "protobuf_java_artifact",
artifact = "com.google.protobuf:protobuf-java:3.2.0"
)
load("@maven//:compat.bzl", "compat_repositories")

maven_jar(
name = "protobuf_java_util_artifact",
artifact = "com.google.protobuf:protobuf-java-util:3.2.0",
)
compat_repositories()

maven_jar(
name = "mockito_artifact",
artifact = "org.mockito:mockito-all:1.10.19",
)
load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")

maven_jar(
name = "prometheus_client_artifact",
artifact = "io.prometheus:simpleclient:0.0.14",
)
# Run grpc_java_repositories after compat_repositories to ensure the
# maven_install-selected dependencies are used.
grpc_java_repositories()

maven_jar(
name = "truth_artifact",
artifact = "com.google.truth:truth:0.28",
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
975 changes: 975 additions & 0 deletions maven_install.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MAVEN_ARTIFACTS = [
"com.google.guava:guava:29.0-jre",
"junit:junit:4.10",
"com.google.protobuf:protobuf-java:3.12.1",
"com.google.protobuf:protobuf-java-util:3.12.1",
"org.mockito:mockito-all:1.10.19",
"io.prometheus:simpleclient:0.9.0",
"com.google.truth:truth:1.0.1",
]
2 changes: 2 additions & 0 deletions src/main/java/me/dinowernli/grpc/prometheus/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

java_library(
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/me/dinowernli/grpc/prometheus/testing/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

java_library(
name = "testing",
testonly = 1,
srcs = glob(["*.java"]),
deps = [
"//src/main/proto:hello_java_proto",
"//src/main/proto:hello_proto_grpc",
"//third_party/grpc",
"//third_party/prometheus",
Expand Down
19 changes: 15 additions & 4 deletions src/main/proto/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
load("@org_pubref_rules_protobuf//java:rules.bzl", "java_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
load("@rules_java//java:defs.bzl", "java_proto_library")

package(default_visibility = ["//visibility:public"])

proto_library(
name = "hello_proto",
srcs = ["hello.proto"],
)

java_proto_library(
name = "hello_proto_grpc",
protos = ["hello.proto"],
with_grpc = True,
name = "hello_java_proto",
deps = [":hello_proto"],
)

java_grpc_library(
name = "hello_proto_grpc",
srcs = [":hello_proto"],
deps = [":hello_java_proto"],
)
27 changes: 24 additions & 3 deletions src/test/java/me/dinowernli/grpc/prometheus/integration/BUILD
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
load("@rules_java//java:defs.bzl", "java_test")

java_test(
name = "tests",
name = "server_test",
size = "small",
srcs = glob(["*.java"]),
srcs = ["MonitoringServerInterceptorIntegrationTest.java"],
test_class = "me.dinowernli.grpc.prometheus.integration.MonitoringServerInterceptorIntegrationTest",
deps = [
"//src/main/java/me/dinowernli/grpc/prometheus",
"//src/main/java/me/dinowernli/grpc/prometheus/testing",
"//src/main/proto:hello_java_proto",
"//src/main/proto:hello_proto_grpc",
"//third_party/grpc",
"//third_party/grpc:grpc_testing",
"//third_party/guava",
"//third_party/prometheus",
"//third_party/testing",
],
)

java_test(
name = "client_test",
size = "small",
srcs = ["MonitoringClientInterceptorIntegrationTest.java"],
test_class = "me.dinowernli.grpc.prometheus.integration.MonitoringClientInterceptorIntegrationTest",
deps = [
"//src/main/java/me/dinowernli/grpc/prometheus",
"//src/main/java/me/dinowernli/grpc/prometheus/testing",
"//src/main/proto:hello_java_proto",
"//src/main/proto:hello_proto_grpc",
"//third_party/grpc",
"//third_party/grpc:grpc_testing",
"//third_party/guava",
"//third_party/netty",
"//third_party/prometheus",
"//third_party/testing",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package me.dinowernli.grpc.prometheus.integration;

import java.io.IOException;

import com.github.dinowernli.proto.grpc.prometheus.HelloProto;
import com.github.dinowernli.proto.grpc.prometheus.HelloProto.HelloResponse;
import com.github.dinowernli.proto.grpc.prometheus.HelloServiceGrpc;
import com.github.dinowernli.proto.grpc.prometheus.HelloServiceGrpc.HelloServiceStub;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.benchmarks.Utils;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.StreamRecorder;
import io.prometheus.client.Collector;
Expand All @@ -22,10 +19,13 @@
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

import static com.google.common.truth.Truth.assertThat;

/** Integration tests for the client-side monitoring pipeline. */
public class MonitoringClientInterceptorIntegrationTest {
private static final String grpcServerName = "grpc-server";
private static final Configuration CHEAP_METRICS = Configuration.cheapMetricsOnly();
private static final Configuration ALL_METRICS = Configuration.allMetrics();

Expand All @@ -34,7 +34,6 @@ public class MonitoringClientInterceptorIntegrationTest {
.setRecipient(RECIPIENT)
.build();

private int grpcPort;
private Server grpcServer;
private CollectorRegistry collectorRegistry;
private StreamRecorder<HelloResponse> responseRecorder;
Expand Down Expand Up @@ -174,16 +173,15 @@ public void overridesHistogramBuckets() throws Throwable {


private HelloServiceStub createClientStub(Configuration configuration) {
return HelloServiceGrpc.newStub(NettyChannelBuilder.forAddress("localhost", grpcPort)
.usePlaintext(true)
return HelloServiceGrpc.newStub(InProcessChannelBuilder.forName(grpcServerName)
.usePlaintext()
.intercept(MonitoringClientInterceptor.create(
configuration.withCollectorRegistry(collectorRegistry)))
.build());
}

private void startServer() {
grpcPort = Utils.pickUnusedPort();
grpcServer = ServerBuilder.forPort(grpcPort)
grpcServer = InProcessServerBuilder.forName(grpcServerName)
.addService(new HelloServiceImpl().bindService())
.build();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

package me.dinowernli.grpc.prometheus.integration;

import java.io.IOException;

import com.github.dinowernli.proto.grpc.prometheus.HelloProto.HelloRequest;
import com.github.dinowernli.proto.grpc.prometheus.HelloProto.HelloResponse;
import com.github.dinowernli.proto.grpc.prometheus.HelloServiceGrpc;
Expand All @@ -12,11 +10,9 @@
import com.google.common.collect.ImmutableList;
import io.grpc.Channel;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.ServerInterceptors;
import io.grpc.benchmarks.Utils;
import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.StreamRecorder;
import io.prometheus.client.Collector.MetricFamilySamples;
Expand All @@ -29,13 +25,16 @@
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

import static com.google.common.truth.Truth.assertThat;

/**
* Integrations tests which make sure that if a service is started with a
* {@link MonitoringServerInterceptor}, then all Prometheus metrics get recorded correctly.
*/
public class MonitoringServerInterceptorIntegrationTest {
private static final String grpcServerName = "grpc-server";
private static final String RECIPIENT = "Dave";
private static final HelloRequest REQUEST = HelloRequest.newBuilder()
.setRecipient(RECIPIENT)
Expand All @@ -46,7 +45,6 @@ public class MonitoringServerInterceptorIntegrationTest {

private CollectorRegistry collectorRegistry;
private Server grpcServer;
private int grpcPort;

@Before
public void setUp() {
Expand Down Expand Up @@ -207,8 +205,7 @@ public void recordsMultipleCalls() throws Throwable {
private void startGrpcServer(Configuration monitoringConfig) {
MonitoringServerInterceptor interceptor = MonitoringServerInterceptor.create(
monitoringConfig.withCollectorRegistry(collectorRegistry));
grpcPort = Utils.pickUnusedPort();
grpcServer = ServerBuilder.forPort(grpcPort)
grpcServer = InProcessServerBuilder.forName(grpcServerName)
.addService(ServerInterceptors.intercept(new HelloServiceImpl().bindService(), interceptor))
.build();
try {
Expand All @@ -235,8 +232,8 @@ private HelloServiceStub createGrpcStub() {
}

private Channel createGrpcChannel() {
return NettyChannelBuilder.forAddress("localhost", grpcPort)
.negotiationType(NegotiationType.PLAINTEXT)
return InProcessChannelBuilder.forName(grpcServerName)
.usePlaintext()
.build();
}
}
17 changes: 7 additions & 10 deletions third_party/grpc/BUILD
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

java_library(
name = "grpc",
licenses = ["permissive"],
exports = [
"@com_google_instrumentation_instrumentation_api//jar",
"@io_grpc_grpc_benchmarks//jar",
"@io_grpc_grpc_context//jar",
"@io_grpc_grpc_core//jar",
"@io_grpc_grpc_netty//jar",
"@io_grpc_grpc_protobuf//jar",
"@io_grpc_grpc_protobuf_lite//jar",
"@io_grpc_grpc_stub//jar",
"@io_grpc_grpc_okhttp//jar",
"@io_grpc_grpc_java//api",
"@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//netty",
"@io_grpc_grpc_java//stub",
],
)

Expand All @@ -21,6 +18,6 @@ java_library(
testonly = 1,
licenses = ["permissive"],
exports = [
"@grpc_testing_artifact//jar",
"@io_grpc_grpc_java//testing",
],
)
Loading

0 comments on commit f30daa5

Please sign in to comment.