mirror of
https://github.com/mii443/prometheus-android-exporter.git
synced 2025-08-22 15:15:35 +00:00
keepalive
This commit is contained in:
4
client/.idea/deploymentTargetDropDown.xml
generated
4
client/.idea/deploymentTargetDropDown.xml
generated
@ -7,11 +7,11 @@
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/X86_64_pixel.avd" />
|
||||
<value value="$USER_HOME$/.android/avd/Pixel_XL_API_31.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-06-05T12:33:39.926473339Z" />
|
||||
<timeTargetWasSelectedWithDropDown value="2023-07-11T15:42:03.701126601Z" />
|
||||
</component>
|
||||
</project>
|
@ -103,49 +103,53 @@ dependencies {
|
||||
|
||||
// room database end ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ktor
|
||||
implementation "io.ktor:ktor-client-android:2.3.0"
|
||||
|
||||
// custom - tests
|
||||
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||
androidTestUtil 'androidx.test:orchestrator:1.4.2'
|
||||
|
||||
// custom - work manager
|
||||
// - work manager
|
||||
implementation 'androidx.work:work-multiprocess:2.8.1'
|
||||
|
||||
def core_version = "1.10.1"
|
||||
|
||||
// custom - prometheus client java library
|
||||
// - prometheus client java library
|
||||
implementation 'io.prometheus:simpleclient:0.16.0'
|
||||
implementation 'io.prometheus:simpleclient_common:0.16.0'
|
||||
|
||||
// custom - kotlin coroutines
|
||||
// - kotlin coroutines
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0-RC"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0-RC"
|
||||
|
||||
// custom - ktor web client
|
||||
// - ktor web client
|
||||
implementation("io.ktor:ktor-client-core:2.3.0")
|
||||
implementation("io.ktor:ktor-client-cio:2.3.0")
|
||||
|
||||
// custom - ktor web server
|
||||
// - ktor web server
|
||||
implementation "io.ktor:ktor-server-cio:2.3.0"
|
||||
implementation "io.ktor:ktor-server-core:2.3.0"
|
||||
implementation "io.ktor:ktor-server-status-pages:2.3.0"
|
||||
|
||||
// custom - view model for Jetpack Compose
|
||||
// - view model for Jetpack Compose
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
|
||||
implementation "androidx.core:core-ktx:$core_version"
|
||||
|
||||
// custom - navigation for Jetpack Compose
|
||||
// - navigation for Jetpack Compose
|
||||
def nav_version = "2.5.3"
|
||||
implementation("androidx.navigation:navigation-compose:$nav_version")
|
||||
|
||||
// custom - work manager
|
||||
// - work manager
|
||||
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
||||
|
||||
// custom - yaml configuration parsing
|
||||
// - yaml configuration parsing
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.1")
|
||||
implementation("com.charleskorn.kaml:kaml:0.54.0")
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
|
||||
|
||||
// custom - protocol buffers
|
||||
// - protocol buffers
|
||||
implementation 'com.google.protobuf:protobuf-javalite:3.20.1'
|
||||
implementation 'com.google.protobuf:protobuf-kotlin-lite:3.20.1'
|
||||
|
||||
|
@ -16,7 +16,8 @@
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.PrometheusAndroidExporter"
|
||||
tools:targetApi="31">
|
||||
tools:targetApi="31"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity
|
||||
android:name=".compose.MainActivity"
|
||||
android:exported="true"
|
||||
|
@ -34,6 +34,7 @@ class ExponentialBackoff {
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
// check for suppressed exceptions
|
||||
Log.d(TAG, e.toString())
|
||||
for (exception in e.suppressed) {
|
||||
if (exception is CancellationException) {
|
||||
throw exception
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.util.Log
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.engine.android.Android
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.request
|
||||
import io.ktor.client.request.setBody
|
||||
@ -13,6 +14,7 @@ import io.prometheus.client.CollectorRegistry
|
||||
import io.prometheus.client.Counter
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
private const val TAG = "PUSHPROX_CLIENT"
|
||||
@ -81,8 +83,9 @@ class PushProxClient(private val pushProxConfig: PushProxConfig) {
|
||||
|
||||
var client: HttpClient? = null
|
||||
try {
|
||||
client = HttpClient()
|
||||
client = createClient()
|
||||
val context: PushProxContext = getPushProxContext(client)
|
||||
|
||||
loop(context)
|
||||
} finally {
|
||||
withContext(NonCancellable) {
|
||||
@ -93,6 +96,16 @@ class PushProxClient(private val pushProxConfig: PushProxConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createClient() : HttpClient {
|
||||
Log.d(TAG, "Creating http client ktor")
|
||||
return HttpClient(Android) {
|
||||
engine {
|
||||
connectTimeout = 10_000
|
||||
socketTimeout = 100_000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPushProxContext(client: HttpClient): PushProxContext {
|
||||
var modifiedProxyURL = pushProxConfig.pushProxUrl.trim('/')
|
||||
|
||||
@ -171,6 +184,7 @@ class PushProxClient(private val pushProxConfig: PushProxConfig) {
|
||||
setBody(pushRequestBody)
|
||||
}
|
||||
|
||||
|
||||
pushProxConfig.countSuccessfulScrape()
|
||||
} catch (e: Exception) {
|
||||
if (e is CancellationException){
|
||||
|
Reference in New Issue
Block a user