Skip to content

Commit

Permalink
Merge pull request #1354 from Netflix/fix-deprecated-usage
Browse files Browse the repository at this point in the history
Avoid using deprecated instrumentation parameters for metrics.
  • Loading branch information
srinivasankavitha committed Dec 6, 2022
2 parents 471dc4f + d6c9a33 commit 4ad5f5e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
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

0 comments on commit 4ad5f5e

Please sign in to comment.