All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.servicemesh.envoycontrol.snapshot.debug.SnapshotDebugInfo.kt Maven / Gradle / Ivy

The newest version!
package pl.allegro.tech.servicemesh.envoycontrol.snapshot.debug

import io.envoyproxy.envoy.config.cluster.v3.Cluster
import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment
import io.envoyproxy.envoy.config.listener.v3.Listener
import io.envoyproxy.envoy.config.route.v3.RouteConfiguration
import net.openhft.hashing.LongHashFunction
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.GlobalSnapshot

fun version(version: String) = Version(
    version,
    // we use the same method of hashing as Envoy to create comparable string
    java.lang.Long.toUnsignedString(LongHashFunction.xx().hashBytes(version.toByteArray(Charsets.US_ASCII)))
)

data class Version(
    val raw: String,
    val metric: String
)

private val emptyVersion = Version("", "")

data class Versions(
    val clusters: Version = emptyVersion,
    val endpoints: Version = emptyVersion,
    val routes: Version = emptyVersion,
    val listeners: Version = emptyVersion
)

data class Snapshot(
    val clusters: Map = emptyMap(),
    val endpoints: Map = emptyMap(),
    val listeners: Map = emptyMap(),
    val routes: Map = emptyMap()
)

data class SnapshotDebugInfo(
    val snapshot: Snapshot,
    val versions: Versions
) {
    constructor(snapshot: io.envoyproxy.controlplane.cache.v3.Snapshot) : this(
        snapshot = Snapshot(
            clusters = snapshot.clusters().resources(),
            endpoints = snapshot.endpoints().resources(),
            listeners = snapshot.listeners().resources(),
            routes = snapshot.routes().resources()
        ),
        versions = Versions(
            clusters = version(snapshot.clusters().version()),
            endpoints = version(snapshot.endpoints().version()),
            listeners = version(snapshot.listeners().version()),
            routes = version(snapshot.routes().version())
        )
    )

    constructor(globalSnapshot: GlobalSnapshot) : this(
        snapshot = Snapshot(
            clusters = globalSnapshot.clusters,
            endpoints = globalSnapshot.endpoints
        ),
        versions = Versions()
    )
}

data class EndpointInfoList(val clusters: List = emptyList())

data class EndpointInfo(val datacenter: String, val ip: String, val port: Int)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy