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

Avoid using deprecated instrumentation parameters for metrics. #1354

Merged
merged 1 commit into from Dec 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -38,14 +38,19 @@ class DgsGraphQLCollatedMetricsTagsProvider(
}

override fun getExecutionTags(
state: DgsGraphQLMetricsInstrumentation.MetricsInstrumentationState,
parameters: InstrumentationExecutionParameters,
result: ExecutionResult,
exception: Throwable?
): Iterable<Tag> {
return Tags.of(executionTagCustomizer.flatMap { it.getExecutionTags(parameters, result, exception) })
return Tags.of(executionTagCustomizer.flatMap { it.getExecutionTags(state, parameters, result, exception) })
}

override fun getFieldFetchTags(parameters: InstrumentationFieldFetchParameters, exception: Throwable?): Iterable<Tag> {
return Tags.of(fieldFetchTagCustomizer.flatMap { it.getFieldFetchTags(parameters, exception) })
override fun getFieldFetchTags(
state: DgsGraphQLMetricsInstrumentation.MetricsInstrumentationState,
parameters: InstrumentationFieldFetchParameters,
exception: Throwable?
): Iterable<Tag> {
return Tags.of(fieldFetchTagCustomizer.flatMap { it.getFieldFetchTags(state, parameters, exception) })
}
}
Expand Up @@ -77,7 +77,7 @@ class DgsGraphQLMetricsInstrumentation(
properties.autotime
.builder(GqlMetric.QUERY.key)
.tags(tagsProvider.getContextualTags())
.tags(tagsProvider.getExecutionTags(parameters, result, exc))
.tags(tagsProvider.getExecutionTags(miState, parameters, result, exc))
.tags(miState.tags())
)
}
Expand All @@ -93,7 +93,7 @@ class DgsGraphQLMetricsInstrumentation(
val tags =
Tags.empty()
.and(tagsProvider.getContextualTags())
.and(tagsProvider.getExecutionTags(parameters, executionResult, null))
.and(tagsProvider.getExecutionTags(miState, parameters, executionResult, null))
.and(miState.tags())

ErrorUtils
Expand Down Expand Up @@ -143,17 +143,18 @@ class DgsGraphQLMetricsInstrumentation(
recordDataFetcherMetrics(
registry,
sampler,
miState,
parameters,
error,
baseTags
)
}
} else {
recordDataFetcherMetrics(registry, sampler, parameters, null, baseTags)
recordDataFetcherMetrics(registry, sampler, miState, parameters, null, baseTags)
}
result
} catch (throwable: Throwable) {
recordDataFetcherMetrics(registry, sampler, parameters, throwable, baseTags)
recordDataFetcherMetrics(registry, sampler, miState, parameters, throwable, baseTags)
throw throwable
}
}
Expand Down Expand Up @@ -197,13 +198,14 @@ class DgsGraphQLMetricsInstrumentation(
private fun recordDataFetcherMetrics(
registry: MeterRegistry,
timerSampler: Timer.Sample,
state: MetricsInstrumentationState,
parameters: InstrumentationFieldFetchParameters,
error: Throwable?,
baseTags: Iterable<Tag>
) {
val recordedTags = Tags
.of(baseTags)
.and(tagsProvider.getFieldFetchTags(parameters, error))
.and(tagsProvider.getFieldFetchTags(state, parameters, error))

timerSampler.stop(
properties
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.netflix.graphql.dgs.metrics.micrometer.tagging

import com.netflix.graphql.dgs.metrics.micrometer.DgsGraphQLMetricsInstrumentation
import graphql.ExecutionResult
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters
import io.micrometer.core.instrument.Tag
Expand All @@ -24,6 +25,7 @@ import io.micrometer.core.instrument.Tag
fun interface DgsExecutionTagCustomizer {

fun getExecutionTags(
state: DgsGraphQLMetricsInstrumentation.MetricsInstrumentationState,
parameters: InstrumentationExecutionParameters,
result: ExecutionResult,
exception: Throwable?
Expand Down
Expand Up @@ -16,11 +16,16 @@

package com.netflix.graphql.dgs.metrics.micrometer.tagging

import com.netflix.graphql.dgs.metrics.micrometer.DgsGraphQLMetricsInstrumentation
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters
import io.micrometer.core.instrument.Tag

@FunctionalInterface
fun interface DgsFieldFetchTagCustomizer {

fun getFieldFetchTags(parameters: InstrumentationFieldFetchParameters, error: Throwable?): Iterable<Tag>
fun getFieldFetchTags(
state: DgsGraphQLMetricsInstrumentation.MetricsInstrumentationState,
parameters: InstrumentationFieldFetchParameters,
error: Throwable?
): Iterable<Tag>
}
Expand Up @@ -16,6 +16,7 @@

package com.netflix.graphql.dgs.metrics.micrometer.tagging

import com.netflix.graphql.dgs.metrics.micrometer.DgsGraphQLMetricsInstrumentation
import graphql.ExecutionResult
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters
Expand All @@ -27,10 +28,15 @@ interface DgsGraphQLMetricsTagsProvider {
fun getContextualTags(): Iterable<Tag> = Tags.empty()

fun getExecutionTags(
state: DgsGraphQLMetricsInstrumentation.MetricsInstrumentationState,
parameters: InstrumentationExecutionParameters,
result: ExecutionResult,
exception: Throwable?
): Iterable<Tag> = Tags.empty()

fun getFieldFetchTags(parameters: InstrumentationFieldFetchParameters, exception: Throwable?): Iterable<Tag> = Tags.empty()
fun getFieldFetchTags(
state: DgsGraphQLMetricsInstrumentation.MetricsInstrumentationState,
parameters: InstrumentationFieldFetchParameters,
exception: Throwable?
): Iterable<Tag> = Tags.empty()
}
Expand Up @@ -17,6 +17,7 @@
package com.netflix.graphql.dgs.metrics.micrometer.tagging

import com.netflix.graphql.dgs.metrics.DgsMetrics.CommonTags.*
import com.netflix.graphql.dgs.metrics.micrometer.DgsGraphQLMetricsInstrumentation
import graphql.ExecutionResult
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters
Expand All @@ -26,6 +27,7 @@ import io.micrometer.core.instrument.Tags
class SimpleGqlOutcomeTagCustomizer : DgsExecutionTagCustomizer, DgsFieldFetchTagCustomizer {

override fun getExecutionTags(
state: DgsGraphQLMetricsInstrumentation.MetricsInstrumentationState,
parameters: InstrumentationExecutionParameters,
result: ExecutionResult,
exception: Throwable?
Expand All @@ -38,6 +40,7 @@ class SimpleGqlOutcomeTagCustomizer : DgsExecutionTagCustomizer, DgsFieldFetchTa
}

override fun getFieldFetchTags(
state: DgsGraphQLMetricsInstrumentation.MetricsInstrumentationState,
parameters: InstrumentationFieldFetchParameters,
error: Throwable?
): Iterable<Tag> {
Expand Down
Expand Up @@ -792,12 +792,12 @@ class MicrometerServletSmokeTest {

@Bean
open fun executionTagCustomizer(): DgsExecutionTagCustomizer {
return DgsExecutionTagCustomizer { _, _, _ -> Tags.of("execution-tag", "foo") }
return DgsExecutionTagCustomizer { _, _, _, _ -> Tags.of("execution-tag", "foo") }
}

@Bean
open fun fieldFetchTagCustomizer(): DgsFieldFetchTagCustomizer {
return DgsFieldFetchTagCustomizer { _, _ -> Tags.of("field-fetch-tag", "foo") }
return DgsFieldFetchTagCustomizer { _, _, _ -> Tags.of("field-fetch-tag", "foo") }
}
}

Expand Down