Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration test for Stackdriver Storage with autoconfiguration #143

Merged
merged 8 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ before_install:
# Encrypted service account file for integration testing
# This file is referenced via GOOGLE_APPLICATION_CREDENTIALS env var
# Ex. travis encrypt-file travis/zipkin-gcp-ci-0d7917f58da7.json
- openssl aes-256-cbc -K $encrypted_0d0e64b78c84_key -iv $encrypted_0d0e64b78c84_iv -in travis/zipkin-gcp-ci-0d7917f58da7.json.enc -out travis/zipkin-gcp-ci-0d7917f58da7.json -d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In spring-cloud-gcp, we explicitly gate on $TRAVIS_SECURE_ENV_VARS. In principle, TRAVIS_PULL_REQUEST could also be used to conditionally decrypt as it's false when not running on a pull request.

Environment variable reference: https://docs.travis-ci.com/user/environment-variables/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea; i'll do the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a similar gate for decrypting file: https://github.com/spring-cloud/spring-cloud-gcp/blob/0513b8784f8828918aacacf18db80a992ae4134c/.travis.yml#L37

i've updated here to use the same gate logic.

# Only attempt to decrypt secret when it's not a PR and has access to secure env var
- if [ "$TRAVIS_SECURE_ENV_VARS" == "true" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
openssl aes-256-cbc -K $encrypted_0d0e64b78c84_key -iv $encrypted_0d0e64b78c84_iv -in travis/zipkin-gcp-ci-0d7917f58da7.json.enc -out travis/zipkin-gcp-ci-0d7917f58da7.json -d;
fi;

# Override default travis to use the maven wrapper; skip license on travis due to #1512
install: ./mvnw install -DskipTests=true -Dlicense.skip=true -Dmaven.javadoc.skip=true -B -V
Expand Down
44 changes: 44 additions & 0 deletions autoconfigure/storage-stackdriver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,49 @@
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin-tests</artifactId>
<scope>test</scope>
</dependency>

<!-- Stackdriver Trace read operations are only available in its v1 API. Use it to validate data was written during integration tests. -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
<version>${grpc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-auth</artifactId>
<version>${grpc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-trace-v1</artifactId>
<version>${grpc-google-cloud-trace.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright 2016-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.storage.stackdriver;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.devtools.cloudtrace.v1.GetTraceRequest;
import com.google.devtools.cloudtrace.v1.Trace;
import com.google.devtools.cloudtrace.v1.TraceServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.auth.MoreCallCredentials;
import org.awaitility.Duration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import zipkin.autoconfigure.storage.stackdriver.ZipkinStackdriverStorageAutoConfiguration;
import zipkin.autoconfigure.storage.stackdriver.ZipkinStackdriverStorageProperties;
import zipkin2.Span;

import java.io.File;
import java.io.IOException;
import java.util.Random;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.assertj.core.api.Assumptions.assumeThatCode;
import static org.awaitility.Awaitility.await;
import static zipkin2.TestObjects.*;
import static zipkin2.TestObjects.TODAY;

/** Integration test against Stackdriver Trace on a real GCP project */
public class ITZipkinStackdriverStorage {
final String projectId = "zipkin-gcp-ci";
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
StackdriverStorage storage;
ZipkinStackdriverStorageProperties storageProperties;
ManagedChannel channel;
TraceServiceGrpc.TraceServiceBlockingStub traceServiceGrpcV1;

@BeforeEach
public void init() throws IOException {
// Application Default credential is configured using the GOOGLE_APPLICATION_CREDENTIALS env var
// See: https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application

String credentialsPath = System.getenv("GOOGLE_APPLICATION_CREDENTIALS");
assumeThat(credentialsPath).isNotBlank();
assumeThat(new File(credentialsPath)).exists();
assumeThatCode(GoogleCredentials::getApplicationDefault).doesNotThrowAnyException();

TestPropertyValues.of(
"zipkin.storage.type:stackdriver",
"zipkin.storage.stackdriver.project-id:" + projectId).applyTo(context);
context.register(
PropertyPlaceholderAutoConfiguration.class,
ZipkinStackdriverStorageAutoConfiguration.class);
context.refresh();
storage = context.getBean(StackdriverStorage.class);
storageProperties = context.getBean(ZipkinStackdriverStorageProperties.class);

GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
.createScoped("https://www.googleapis.com/auth/cloud-platform");

channel = ManagedChannelBuilder.forTarget("cloudtrace.googleapis.com")
.build();
traceServiceGrpcV1 = TraceServiceGrpc.newBlockingStub(channel)
.withCallCredentials(MoreCallCredentials.from(credentials));

}

@AfterEach
public void close() {
context.close();

if (channel != null) {
channel.shutdownNow();
}
}

@Test
public void healthCheck() {
assertThat(storage.check().ok()).isTrue();
}

@Test
public void spanConsumer() throws IOException {
Random random = new Random();
Span span = Span.newBuilder()
.traceId(random.nextLong(), random.nextLong())
.parentId("1")
.id("2")
.name("get")
.kind(Span.Kind.CLIENT)
.localEndpoint(FRONTEND)
.remoteEndpoint(BACKEND)
.timestamp((TODAY + 50L) * 1000L)
.duration(200000L)
.addAnnotation((TODAY + 100L) * 1000L, "foo")
.putTag("http.path", "/api")
.putTag("clnt/finagle.version", "6.45.0")
.build();


storage.spanConsumer().accept(asList(span)).execute();

Trace trace = await()
.atLeast(Duration.ONE_SECOND)
.atMost(Duration.TEN_SECONDS)
.pollInterval(Duration.ONE_SECOND)
.ignoreExceptionsMatching(e ->
e instanceof StatusRuntimeException &&
((StatusRuntimeException) e).getStatus().getCode() == Status.Code.NOT_FOUND
)
.until(() -> traceServiceGrpcV1.getTrace(GetTraceRequest.newBuilder()
.setProjectId(projectId)
.setTraceId(span.traceId())
.build()), t -> t.getSpansCount() == 1);

assertThat(trace.getSpans(0).getSpanId()).isEqualTo(2);
assertThat(trace.getSpans(0).getParentSpanId()).isEqualTo(1);
}

}
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
<zipkin.version>2.16.2</zipkin.version>
<zipkin-reporter.version>2.10.2</zipkin-reporter.version>
<brave.version>5.6.10</brave.version>
<grpc.version>1.22.1</grpc.version>
<grpc.version>1.22.2</grpc.version>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is updated to match armeria's grpc version.

<guava.version>28.0-jre</guava.version>
<protobuf.version>3.7.1</protobuf.version>
<awaitility.version>3.1.6</awaitility.version>

<!-- only used for protos, we could possibly obviate this if a problem -->
<grpc-google-cloud-trace.version>0.69.0</grpc-google-cloud-trace.version>
Expand Down
2 changes: 1 addition & 1 deletion sender-stackdriver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>3.1.6</version>
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.assertj.core.api.Assumptions.assumeThatCode;
import static org.awaitility.Awaitility.await;
import static zipkin2.TestObjects.FRONTEND;
import static zipkin2.TestObjects.BACKEND;
Expand All @@ -60,6 +61,7 @@ public void setUp() throws IOException {
String credentialsPath = System.getenv("GOOGLE_APPLICATION_CREDENTIALS");
assumeThat(credentialsPath).isNotBlank();
assumeThat(new File(credentialsPath)).exists();
assumeThatCode(GoogleCredentials::getApplicationDefault).doesNotThrowAnyException();

credentials = GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singletonList("https://www.googleapis.com/auth/trace.append"));
Expand Down Expand Up @@ -137,8 +139,8 @@ public void sendSpans() {
.setTraceId(span.traceId())
.build()), t -> t.getSpansCount() == 1);

assertThat(span.id()).isEqualTo("0000000000000002");
assertThat(span.parentId()).isEqualTo("0000000000000001");
assertThat(trace.getSpans(0).getSpanId()).isEqualTo(2);
assertThat(trace.getSpans(0).getParentSpanId()).isEqualTo(1);
}

@Test
Expand Down