-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first functioning version, still needs lots of polishing
- Loading branch information
fabito
committed
Dec 21, 2016
1 parent
88c2210
commit 8af5b22
Showing
43 changed files
with
1,497 additions
and
172 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
# dropwizard-gcp | ||
|
||
[![Build Status][travis-image]][travis-url] | ||
|
||
Dropwizard libraries for applications running on Google Cloud Platform | ||
|
||
* logging | ||
* tracing | ||
* metrics | ||
|
||
[travis-image]: https://travis-ci.org/fabito/dropwizard-gcp.svg?branch=master | ||
[travis-url]: https://travis-ci.org/fabito/dropwizard-gcp |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apply plugin: 'java' | ||
|
||
sourceCompatibility = 1.8 | ||
|
||
project.ext { | ||
cloudTrace = "0.2.2" | ||
} | ||
|
||
dependencies { | ||
|
||
compile "io.dropwizard:dropwizard-client:${dropwizardVersion}" | ||
compile ('org.glassfish.hk2:hk2-extras:2.5.0-b30') | ||
|
||
compile group: 'com.google.cloud.trace', name: 'trace-grpc-api-service', version: cloudTrace | ||
compile group: 'com.google.cloud.trace', name: 'core', version: cloudTrace | ||
compile group: 'com.google.cloud.trace', name: 'annotation', version: cloudTrace | ||
compile group: 'com.google.cloud.trace', name:'guice-annotation', version: cloudTrace | ||
|
||
compile group: 'com.google.auth', name: 'google-auth-library-oauth2-http', version: '0.4.0' | ||
|
||
compile group: 'io.grpc', name: 'grpc-netty', version: '1.0.1' | ||
compile group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: '1.1.33.Fork23' | ||
|
||
testCompile group: 'junit', name: 'junit', version: '4.11' | ||
} |
23 changes: 23 additions & 0 deletions
23
dropwizard-stackdriver-trace/src/main/java/com/google/cloud/trace/http/HttpHeaders.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,23 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// | ||
// 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 com.google.cloud.trace.http; | ||
|
||
/** | ||
* Common HTTP header constants. | ||
*/ | ||
class HttpHeaders { | ||
static final String USER_AGENT = "User-Agent"; | ||
static final String CONTENT_LENGTH = "Content-Length"; | ||
} |
30 changes: 30 additions & 0 deletions
30
dropwizard-stackdriver-trace/src/main/java/com/google/cloud/trace/http/HttpLabels.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,30 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// | ||
// 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 com.google.cloud.trace.http; | ||
|
||
/** | ||
* Common HTTP label constants. | ||
*/ | ||
public class HttpLabels { | ||
public static final String REQUEST_SIZE = "/request/size"; | ||
public static final String RESPONSE_SIZE = "/response/size"; | ||
public static final String HTTP_METHOD = "/http/method"; | ||
public static final String HTTP_STATUS_CODE = "/http/status_code"; | ||
public static final String HTTP_URL = "/http/url"; | ||
public static final String HTTP_HOST = "/http/host"; | ||
public static final String HTTP_REDIRECTED_URL = "/http/redirected_url"; | ||
public static final String HTTP_USER_AGENT = "/http/user_agent"; | ||
public static final String HTTP_CLIENT_PROTOCOL = "/http/client_protocol"; | ||
} |
48 changes: 48 additions & 0 deletions
48
dropwizard-stackdriver-trace/src/main/java/com/google/cloud/trace/http/HttpRequest.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,48 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// | ||
// 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 com.google.cloud.trace.http; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* Common interface for HTTP requests. | ||
*/ | ||
public interface HttpRequest { | ||
|
||
/** | ||
* The HTTP method of the HTTP request.. | ||
* @return The HTTP method. | ||
*/ | ||
String getMethod(); | ||
|
||
/** | ||
* The URI being requested. | ||
* @return The URI being requested. | ||
*/ | ||
URI getURI(); | ||
|
||
/** | ||
* Get a header value. | ||
* @param name The name of the header. | ||
* @return The value of the header. | ||
*/ | ||
String getHeader(String name); | ||
|
||
/** | ||
* The HTTP protocol being used by the client (e.g. HTTP, SPDY). | ||
* @return The HTTP protocol being used. | ||
*/ | ||
String getProtocol(); | ||
} |
34 changes: 34 additions & 0 deletions
34
dropwizard-stackdriver-trace/src/main/java/com/google/cloud/trace/http/HttpResponse.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,34 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// | ||
// 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 com.google.cloud.trace.http; | ||
|
||
/** | ||
* Common interface for HTTP responses. | ||
*/ | ||
public interface HttpResponse { | ||
|
||
/** | ||
* Get a header value. | ||
* @param name The name of the header. | ||
* @return The value of the header. | ||
*/ | ||
String getHeader(String name); | ||
|
||
/** | ||
* Get the status code. | ||
* @return The status code from the response. | ||
*/ | ||
int getStatus(); | ||
} |
60 changes: 60 additions & 0 deletions
60
...ckdriver-trace/src/main/java/com/google/cloud/trace/http/TraceHttpRequestInterceptor.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,60 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// | ||
// 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 com.google.cloud.trace.http; | ||
|
||
import com.google.cloud.trace.Trace; | ||
import com.google.cloud.trace.Tracer; | ||
import com.google.cloud.trace.core.Labels; | ||
import com.google.cloud.trace.core.TraceContext; | ||
|
||
/** | ||
* An interceptor that records tracing information for HTTP requests. Should be used along with | ||
* {@link TraceHttpResponseInterceptor}. | ||
*/ | ||
public class TraceHttpRequestInterceptor { | ||
|
||
private final Tracer tracer; | ||
|
||
public TraceHttpRequestInterceptor() { | ||
this(Trace.getTracer()); | ||
} | ||
|
||
public TraceHttpRequestInterceptor(Tracer tracer) { | ||
this.tracer = tracer; | ||
} | ||
|
||
/** | ||
* Starts a span for an HTTP request and record relevant labels. | ||
* @param request The HTTP request. | ||
* @return The new TraceContext | ||
*/ | ||
public TraceContext process(HttpRequest request) { | ||
Labels.Builder labels = Labels.builder(); | ||
TraceInterceptorUtil | ||
.annotateIfNotEmpty(labels, HttpLabels.HTTP_METHOD, request.getURI().toString()); | ||
labels.add(HttpLabels.HTTP_METHOD, request.getMethod()); | ||
TraceInterceptorUtil | ||
.annotateIfNotEmpty(labels, HttpLabels.HTTP_URL, request.getURI().toString()); | ||
TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.HTTP_CLIENT_PROTOCOL, | ||
request.getProtocol()); | ||
TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.HTTP_USER_AGENT, | ||
request.getHeader(HttpHeaders.USER_AGENT)); | ||
TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.REQUEST_SIZE, | ||
request.getHeader(HttpHeaders.CONTENT_LENGTH)); | ||
TraceContext traceContext = tracer.startSpan(request.getURI().getPath()); | ||
tracer.annotateSpan(traceContext, labels.build()); | ||
return traceContext; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...kdriver-trace/src/main/java/com/google/cloud/trace/http/TraceHttpResponseInterceptor.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,53 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// | ||
// 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 com.google.cloud.trace.http; | ||
|
||
import com.google.cloud.trace.Trace; | ||
import com.google.cloud.trace.Tracer; | ||
import com.google.cloud.trace.core.Labels; | ||
import com.google.cloud.trace.core.TraceContext; | ||
|
||
/** | ||
* An interceptor that records tracing information for HTTP responses. Should be used along with | ||
* {@link TraceHttpRequestInterceptor}. | ||
*/ | ||
public class TraceHttpResponseInterceptor { | ||
private final Tracer tracer; | ||
|
||
public TraceHttpResponseInterceptor() { | ||
this(Trace.getTracer()); | ||
} | ||
|
||
public TraceHttpResponseInterceptor(Tracer tracer) { | ||
this.tracer = tracer; | ||
} | ||
|
||
/** | ||
* Ends a span for an HTTP request and records relevant labels. | ||
* @param response The HTTP response. | ||
* @param traceContext The TraceContext for the request. | ||
*/ | ||
public void process(HttpResponse response, TraceContext traceContext) { | ||
if (traceContext == null) { | ||
return; | ||
} | ||
Labels.Builder labels = Labels.builder(); | ||
TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.RESPONSE_SIZE, | ||
response.getHeader(HttpHeaders.CONTENT_LENGTH)); | ||
labels.add(HttpLabels.HTTP_STATUS_CODE, Integer.toString(response.getStatus())); | ||
tracer.annotateSpan(traceContext, labels.build()); | ||
tracer.endSpan(traceContext); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ard-stackdriver-trace/src/main/java/com/google/cloud/trace/http/TraceInterceptorUtil.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,25 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// | ||
// 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 com.google.cloud.trace.http; | ||
|
||
import com.google.cloud.trace.core.Labels; | ||
|
||
class TraceInterceptorUtil { | ||
static void annotateIfNotEmpty(Labels.Builder labels, String key, String value) { | ||
if (value != null && value.length() > 0) { | ||
labels.add(key, value); | ||
} | ||
} | ||
} |
Oops, something went wrong.