Skip to content

Commit

Permalink
[IJ Plugin] Fix high latency field inspection (#6142)
Browse files Browse the repository at this point in the history
* Fix ApolloKotlinService.Id toString/fromString, so comparison with ApolloKotlinServiceConfiguration works.

* Try upstream services when getting latencies
  • Loading branch information
BoD authored Sep 10, 2024
1 parent 7629cb1 commit 063d17f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 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 @@ -52,21 +55,19 @@ data class ApolloKotlinService(
val serviceName: String = "",
) {
override fun toString(): String {
val formattedPath = gradleProjectPath.split(":").filterNot { it.isEmpty() }.joinToString("-")
return "$formattedPath/$serviceName"
return "$gradleProjectPath/$serviceName"
}

companion object {
fun fromString(string: String): Id? {
val split = string.split("/")
val split = string.split("/", limit = 2)
if (split.size != 2) return null
return Id(split[0], split[1])
}
}
}

val id
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 063d17f

Please sign in to comment.