-
Notifications
You must be signed in to change notification settings - Fork 55
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
saturnism
merged 8 commits into
openzipkin:master
from
saturnism:it-stackdriver-storage
Sep 10, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b1afe04
Added integration test for Stackdriver Storage with autoconfiguration
saturnism 0e10704
Ignore decryption failures on PRs
saturnism 8468f9a
When using `openssl` to decrypt file, it always creates target file.
saturnism 5527604
fix integration tests to validate results returned from stackdriver
saturnism ff32035
gate decryption w/ secure env var
saturnism 4722f10
fix awaitility property name
saturnism 3a03505
missed a ;
saturnism abba080
updated the gate and comment
saturnism File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
...age-stackdriver/src/test/java/zipkin2/storage/stackdriver/ITZipkinStackdriverStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.