Skip to content

Commit

Permalink
Try upstream services when getting latencies
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Sep 10, 2024
1 parent 4f0be26 commit b8cf0d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ data class ApolloKotlinService(

@XCollection
val endpointHeaders: Map<String, String>? = null,

@XCollection
val upstreamServiceIds: List<Id> = emptyList(),
) {
data class Id(
@Attribute
Expand All @@ -67,5 +70,4 @@ data class ApolloKotlinService(
val id: Id
@Transient
get() = Id(gradleProjectPath, serviceName)

}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class GradleToolingModelService(
.distinct(),
endpointUrl = serviceInfo.endpointUrlCompat(toolingModel),
endpointHeaders = serviceInfo.endpointHeadersCompat(toolingModel),
upstreamServiceIds = upstreamApolloKotlinServices.map { it.id }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,20 @@ class FieldInsightsServiceImpl(private val project: Project) : FieldInsightsServ
return fieldLatenciesByService.isNotEmpty()
}

private fun getFieldLatenciesForService(serviceId: ApolloKotlinService.Id): FieldInsights.FieldLatencies? {
if (fieldLatenciesByService.containsKey(serviceId)) {
return fieldLatenciesByService[serviceId]
}
// Try upstream services
val apolloKotlinService = GradleToolingModelService.getApolloKotlinServices(project).firstOrNull { it.id == serviceId } ?: return null
for (upstreamServiceId in apolloKotlinService.upstreamServiceIds) {
return getFieldLatenciesForService(upstreamServiceId) ?: continue
}
return null
}

override fun getLatency(serviceId: ApolloKotlinService.Id, typeName: String, fieldName: String): Double? {
return fieldLatenciesByService[serviceId]?.getLatency(parentType = typeName, fieldName = fieldName)
return getFieldLatenciesForService(serviceId)?.getLatency(parentType = typeName, fieldName = fieldName)
}

private fun refreshInspections() {
Expand Down

0 comments on commit b8cf0d3

Please sign in to comment.