-
Notifications
You must be signed in to change notification settings - Fork 67
feat: Introduce interfaces for metrics instrumentation #2403
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
Changes from 28 commits
2ae69f7
6671379
cd9f387
5eccd09
c2573b6
292beae
9cfd35e
4d19614
be5b7b3
527985f
56c9999
d249b66
145ad30
5c30048
57571b2
3e2a771
3f24049
09c7c7b
d1bf7bd
fed50c7
69e8a90
f771d7e
d714cf4
7977511
39d0c69
8ff9bb5
0efbeba
6171779
2678682
9e32b79
0483500
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Google LLC nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.google.api.gax.tracing; | ||
|
||
import com.google.api.core.BetaApi; | ||
import com.google.api.core.InternalApi; | ||
import com.google.api.gax.rpc.StubSettings; | ||
import com.google.auto.value.AutoValue; | ||
|
||
/** A value class to represent the name of the RPC method in an {@link ApiTracer}. */ | ||
@BetaApi | ||
@InternalApi | ||
@AutoValue | ||
public abstract class MethodName { | ||
/** | ||
* Creates a new instance of the RPC method name. | ||
* | ||
* @param serviceName The name of the service. In general this will be GAPIC generated service | ||
* name {@link StubSettings#getServiceName()}. However, in some cases, when the GAPIC | ||
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. @blakeli0 I am now having some second thoughts on the
even though the intended result for this probably should be Not something blocking this PR, but just wondering your thoughts on this. 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. 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.
I don't want to say what the intended name should be. I think it might be a bit weird for customers since we probably aren't providing consistent service names. java-asset's serviceName is cloudasset (link above) I think most services would have the service name of java-{serviceName} except for asset and possibly a few others. It might not be a big concern after all, but something just doesn't sit right with me knowing that serviceName is parsed from a URI (default_host value) and not the package name or some config value (name_pretty or api name). 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. I spent sometime while working on the dashboard on service names, and they are not of the type "java-{serviceName}". See column A in this sheet. In the dashboard too, we are deriving the service name from the default_host value. 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. FYI, your link doesn't work for me. Seems like there is no defined Not blocking this PR, but it would be great if there was an official definition for serviceName. Perhaps a question for the core team. 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. @lqiu96 I think the term 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. Ok, to wrap up the conversation above: I'll add some additional docs clarifying the intended use case (constructing the endpoint) and how the this value is constructed (from the config files). It is fine that serviceName in the library (pulled from 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.
Correct. The library/repo name may not always be in the format of |
||
* generated service is wrapped, this will be overridden to specify the manually written | ||
* wrapper's name. | ||
* @param methodName The name of the logical operation being traced. | ||
*/ | ||
public static MethodName of(String serviceName, String methodName) { | ||
return new AutoValue_MethodName(serviceName, methodName); | ||
} | ||
|
||
/** The name of the service. ie BigtableData */ | ||
public abstract String getServiceName(); | ||
|
||
/** The name of the logical operation being traced. ie. ReadRows. */ | ||
public abstract String getMethodName(); | ||
|
||
@Override | ||
public String toString() { | ||
return getServiceName() + "." + getMethodName(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Google LLC nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.google.api.gax.tracing; | ||
|
||
import com.google.api.core.BetaApi; | ||
import com.google.api.core.InternalApi; | ||
import java.util.Map; | ||
|
||
/** | ||
* Provides an interface for metrics recording. The implementer is expected to use an observability | ||
* framework, e.g. OpenTelemetry | ||
*/ | ||
@BetaApi | ||
lqiu96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@InternalApi | ||
public interface MetricsRecorder { | ||
|
||
/** TODO: Add Javadoc */ | ||
blakeli0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default void recordAttemptLatency(double attemptLatency, Map<String, String> attributes) {} | ||
|
||
/** TODO: Add Javadoc */ | ||
default void recordAttemptCount(long count, Map<String, String> attributes) {} | ||
|
||
/** TODO: Add Javadoc */ | ||
default void recordOperationLatency(double operationLatency, Map<String, String> attributes) {} | ||
|
||
/** TODO: Add Javadoc */ | ||
default void recordOperationCount(long count, Map<String, String> attributes) {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Google LLC nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.google.api.gax.tracing; | ||
|
||
import com.google.api.core.BetaApi; | ||
import com.google.api.core.InternalApi; | ||
|
||
/** | ||
* This class computes generic metrics that can be observed in the lifecycle of an RPC operation. | ||
* The responsibility of recording metrics should delegate to {@link MetricsRecorder}, hence this | ||
* class should not have any knowledge about the observability framework used for metrics recording. | ||
*/ | ||
@BetaApi | ||
@InternalApi | ||
public class MetricsTracer implements ApiTracer { | ||
|
||
public MetricsTracer(MethodName methodName, MetricsRecorder metricsRecorder) {} | ||
|
||
/** TODO: Add Javadoc */ | ||
void addAttributes(String key, String value) {}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* * Neither the name of Google LLC nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.google.api.gax.tracing; | ||
|
||
import com.google.api.core.BetaApi; | ||
import com.google.api.core.InternalApi; | ||
|
||
/** | ||
* A {@link ApiTracerFactory} to build instances of {@link MetricsTracer}. | ||
* | ||
* <p>This class wraps the {@link MetricsRecorder} and pass it to {@link MetricsTracer}. It will be | ||
* used to record metrics in {@link MetricsTracer}. | ||
* | ||
* <p>This class is thread safe. | ||
*/ | ||
@BetaApi | ||
@InternalApi | ||
public class MetricsTracerFactory implements ApiTracerFactory { | ||
protected MetricsRecorder metricsRecorder; | ||
|
||
public MetricsTracerFactory(MetricsRecorder metricsRecorder) { | ||
this.metricsRecorder = metricsRecorder; | ||
} | ||
|
||
@Override | ||
public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) { | ||
return new MetricsTracer( | ||
MethodName.of(spanName.getClientName(), spanName.getMethodName()), metricsRecorder); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.