Skip to content

Commit

Permalink
Cleanup grpc object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pambrose committed May 10, 2020
1 parent e55f2b8 commit a31307d
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 115 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ dependencies {

/*
sourceSets {
main.java.srcDirs = ['src/main/java']
main.kotlin.srcDirs = ['src/main/kotlin']
test.java.srcDirs = ['src/test/java']
test.kotlin.srcDirs = ['src/test/kotlin']
main.resources.srcDirs = ['src/main/resources']
test.resources.srcDirs = ['src/main/testresources']
main.java.srcDirs += ['src/main/java']
main.kotlin.srcDirs += ['src/main/kotlin']
test.java.srcDirs += ['src/test/java']
test.kotlin.srcDirs += ['src/test/kotlin']
main.resources.srcDirs += ['src/main/resources']
test.resources.srcDirs += ['src/main/testresources']
}
*/

Expand Down
33 changes: 18 additions & 15 deletions src/main/kotlin/io/prometheus/agent/AgentGrpcService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,30 +152,33 @@ internal class AgentGrpcService(private val agent: Agent,

fun registerAgent(initialConnectionLatch: CountDownLatch) {
val request = newRegisterAgentRequest(agent.agentId, agent.agentName, hostName)
blockingStub.registerAgent(request).also { response ->
agent.markMsgSent()
if (!response.valid)
throw RequestFailureException("registerAgent() - ${response.reason}")
}
blockingStub.registerAgent(request)
.also { response ->
agent.markMsgSent()
if (!response.valid)
throw RequestFailureException("registerAgent() - ${response.reason}")
}
initialConnectionLatch.countDown()
}

fun pathMapSize(): Int {
val request = GrpcObjects.newPathMapSizeRequest(agent.agentId)
return blockingStub.pathMapSize(request).run {
agent.markMsgSent()
pathCount
}
return blockingStub.pathMapSize(request)
.run {
agent.markMsgSent()
pathCount
}
}

fun registerPathOnProxy(path: String): Long {
val request = GrpcObjects.newRegisterPathRequest(agent.agentId, path)
return blockingStub.registerPath(request).run {
agent.markMsgSent()
if (!valid)
throw RequestFailureException("registerPath() - $reason")
pathId
}
return blockingStub.registerPath(request)
.run {
agent.markMsgSent()
if (!valid)
throw RequestFailureException("registerPath() - $reason")
pathId
}
}

fun unregisterPathOnProxy(path: String) {
Expand Down

0 comments on commit a31307d

Please sign in to comment.