-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send metric when kube fails (#10190)
- Loading branch information
1 parent
049d598
commit 85fd659
Showing
3 changed files
with
240 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
airbyte-workload-launcher/src/test/kotlin/pods/OrchestratorPodLauncherTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package pods | ||
|
||
import io.airbyte.config.ResourceRequirements | ||
import io.airbyte.featureflag.FeatureFlagClient | ||
import io.airbyte.metrics.lib.MetricAttribute | ||
import io.airbyte.metrics.lib.MetricClient | ||
import io.airbyte.metrics.lib.OssMetricsRegistry | ||
import io.airbyte.workers.process.KubeContainerInfo | ||
import io.airbyte.workers.process.KubePodInfo | ||
import io.airbyte.workload.launcher.pods.OrchestratorPodLauncher | ||
import io.fabric8.kubernetes.client.KubernetesClient | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.Assertions.assertFalse | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import java.lang.IllegalStateException | ||
import java.time.Duration | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class OrchestratorPodLauncherTest { | ||
@MockK | ||
private lateinit var kubernetesClient: KubernetesClient | ||
|
||
@MockK | ||
private lateinit var featureFlagClient: FeatureFlagClient | ||
|
||
@MockK | ||
private lateinit var metricClient: MetricClient | ||
|
||
private lateinit var orchestratorPodLauncher: OrchestratorPodLauncher | ||
|
||
@BeforeEach | ||
fun setup() { | ||
orchestratorPodLauncher = | ||
OrchestratorPodLauncher( | ||
kubernetesClient, | ||
featureFlagClient, | ||
"", | ||
"", | ||
"", | ||
"", | ||
"", | ||
"", | ||
"", | ||
listOf(), | ||
listOf(), | ||
mapOf(), | ||
metricClient, | ||
) | ||
|
||
every { featureFlagClient.stringVariation(any(), any()) } returns "" | ||
every { kubernetesClient.pods() } throws IllegalStateException() | ||
every { metricClient.count(any(), any(), any()) } returns Unit | ||
} | ||
|
||
@Test | ||
fun `test fail to create pod`() { | ||
assertThrows<IllegalStateException> { | ||
orchestratorPodLauncher.create( | ||
mapOf(), | ||
ResourceRequirements(), | ||
mapOf(), | ||
KubePodInfo("", "", KubeContainerInfo("", "")), | ||
) | ||
} | ||
|
||
checkMetricSend("pod_create") | ||
} | ||
|
||
@Test | ||
fun `test fail to wait for pod init`() { | ||
assertThrows<IllegalStateException> { | ||
orchestratorPodLauncher.waitForPodInit( | ||
mapOf(), | ||
Duration.ZERO, | ||
) | ||
} | ||
|
||
checkMetricSend("wait") | ||
} | ||
|
||
@Test | ||
fun `test fail to wait for pod ready or terminal`() { | ||
assertThrows<IllegalStateException> { | ||
orchestratorPodLauncher.waitForPodReadyOrTerminal( | ||
mapOf(), | ||
Duration.ZERO, | ||
) | ||
} | ||
|
||
checkMetricSend("wait") | ||
} | ||
|
||
@Test | ||
fun `test fail to check if pod exist`() { | ||
assertFalse(orchestratorPodLauncher.podsExist(mapOf())) | ||
|
||
checkMetricSend("list") | ||
} | ||
|
||
@Test | ||
fun `test fail to delete pod`() { | ||
assertThrows<IllegalStateException> { | ||
orchestratorPodLauncher.deletePods( | ||
mapOf(), | ||
) | ||
} | ||
|
||
checkMetricSend("delete") | ||
} | ||
|
||
private fun checkMetricSend(tag: String) { | ||
val attributes: List<MetricAttribute> = listOf(MetricAttribute("operation", tag)) | ||
val attributesArray = attributes.toTypedArray<MetricAttribute>() | ||
verify { | ||
metricClient.count(OssMetricsRegistry.WORKLOAD_LAUNCHER_KUBE_ERROR, 1, *attributesArray) | ||
} | ||
} | ||
} |