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

Add client version to labels #346

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ class EthereumLabelsDetector(
)
}

private fun detectNodeType(): Mono<Pair<String, String>?> {
private fun detectNodeType(): Flux<Pair<String, String>?> {
return reader
.read(JsonRpcRequest("web3_clientVersion", listOf()))
.flatMap(JsonRpcResponse::requireResult)
.mapNotNull {
val node = objectMapper.readValue<JsonNode>(it)
.map { objectMapper.readValue<JsonNode>(it) }
.flatMapMany { node ->
val labels = mutableListOf<Pair<String, String>>()
if (node.isTextual) {
nodeType(node.textValue())?.run {
"client_type" to this
clientType(node.textValue())?.let {
labels.add("client_type" to it)
}
clientVersion(node.textValue())?.let {
labels.add("client_version" to it)
}
} else {
null
}

Flux.fromIterable(labels)
}
.onErrorResume { Mono.empty() }
}
Expand All @@ -60,14 +64,23 @@ class EthereumLabelsDetector(
).flatMap(JsonRpcResponse::requireResult)
}

private fun nodeType(nodeType: String): String? {
return if (nodeType.contains("erigon", true)) {
private fun clientVersion(client: String): String? {
val firstSlash = client.indexOf("/")
val secondSlash = client.indexOf("/", firstSlash + 1)
if (firstSlash == -1 || secondSlash == -1 || secondSlash < firstSlash) {
return null
}
return client.substring(firstSlash + 1, secondSlash)
}

private fun clientType(client: String): String? {
return if (client.contains("erigon", true)) {
"erigon"
} else if (nodeType.contains("geth", true)) {
} else if (client.contains("geth", true)) {
"geth"
} else if (nodeType.contains("bor", true)) {
} else if (client.contains("bor", true)) {
"bor"
} else if (nodeType.contains("nethermind", true)) {
} else if (client.contains("nethermind", true)) {
"nethermind"
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ class EthereumLabelsDetectorSpec extends Specification {
StepVerifier.create(act)
.expectNext(
new Pair<String, String>("client_type", clientType),
new Pair<String, String>("client_version", version),
new Pair<String, String>("archive", "true")
)
.expectComplete()
.verify(Duration.ofSeconds(1))
where:
response | clientType
"Nethermind/v1.19.3+e8ac1da4/linux-x64/dotnet7.0.8" | "nethermind"
"Geth/v1.12.0-stable-e501b3b0/linux-amd64/go1.20.3" | "geth"
"Erigon/v1.12.0-stable-e501b3b0/linux-amd64/go1.20.3" | "erigon"
"Bor/v0.4.0/linux-amd64/go1.19.10" | "bor"
response | clientType | version
"Nethermind/v1.19.3+e8ac1da4/linux-x64/dotnet7.0.8" | "nethermind" | "v1.19.3+e8ac1da4"
"Geth/v1.12.0-stable-e501b3b0/linux-amd64/go1.20.3" | "geth" | "v1.12.0-stable-e501b3b0"
"Erigon/v1.12.0-stable-e501b3b0/linux-amd64/go1.20.3" | "erigon" | "v1.12.0-stable-e501b3b0"
"Bor/v0.4.0/linux-amd64/go1.19.10" | "bor" | "v0.4.0"
}

def "No any label"() {
Expand Down
Loading