prometheus remote write works

This commit is contained in:
Martin Ptáček
2023-06-05 16:16:09 +02:00
parent 2378145dc4
commit c22deb7d10
6 changed files with 168 additions and 8 deletions

123
client/.idea/codeStyles/Project.xml generated Normal file
View File

@ -0,0 +1,123 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/X86_64_pixel.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-06-05T12:33:39.926473339Z" />
</component>
</project>

View File

@ -101,7 +101,8 @@ dependencies {
implementation 'com.google.protobuf:protobuf-javalite:3.20.1'
implementation 'com.google.protobuf:protobuf-kotlin-lite:3.20.1'
// snappy compression for remote write
implementation 'org.iq80.snappy:snappy:0.4'
implementation 'androidx.core:core-ktx:1.10.1'

View File

@ -51,6 +51,7 @@ class PromWorker(
private suspend fun startServices(config : PromConfiguration){
var deferred = coroutineScope {
Log.v(TAG, "before launched")
if(config.prometheusServerEnabled){
launch{
PrometheusServer.start(
@ -59,6 +60,8 @@ class PromWorker(
}
}
Log.v(TAG, "launched")
if(config.pushproxEnabled){
pushProxClient = PushProxClient(
PushProxConfig(

View File

@ -13,6 +13,8 @@ import remote.write.RemoteWrite.Label
import remote.write.RemoteWrite.TimeSeries
import remote.write.RemoteWrite.WriteRequest
import org.iq80.snappy.Snappy
private const val TAG : String = "REMOTE_WRITE_SENDER"
data class RemoteWriteConfiguration(
val scrape_interval : Int,
@ -28,12 +30,21 @@ class RemoteWriteSender(private val config : RemoteWriteConfiguration) {
val label : Label = Label.newBuilder()
.setName("labelNameTest")
.setValue("labelValueTest").build()
val nameLabel : Label = Label.newBuilder()
.setName("__name__")
.setValue("testremotewritemetric2")
.build()
val secondsOffset = 3555
val sample : RemoteWrite.Sample = RemoteWrite.Sample.newBuilder()
.setValue(55.0)
.setTimestamp(System.currentTimeMillis()).build()
.setValue(58.0)
.setTimestamp(System.currentTimeMillis() - 1000 * secondsOffset).build()
val timeSeries: TimeSeries = TimeSeries.newBuilder()
.addLabels(label)
.addLabels(nameLabel)
.addSamples(sample)
.build()
@ -44,16 +55,15 @@ class RemoteWriteSender(private val config : RemoteWriteConfiguration) {
return request.toByteArray()
}
private fun encdeWithSnappy(data : ByteArray) : ByteArray {
// TODO implement this
// github.com/xerial/snappy-java
return data
private fun encodeWithSnappy(data : ByteArray) : ByteArray {
return Snappy.compress(data)
}
suspend fun sendTestRequest(){
Log.v(TAG, "sending to prometheus now")
val client = HttpClient()
val response = client.post(config.remote_write_endpoint){
setBody(getRequestBody())
setBody(encodeWithSnappy(getRequestBody()))
headers{
append(HttpHeaders.ContentEncoding, "snappy")
append(HttpHeaders.ContentType, "application/protobuf")
@ -63,6 +73,7 @@ class RemoteWriteSender(private val config : RemoteWriteConfiguration) {
}
Log.v(TAG, "Response status: ${response.status.toString()}")
Log.v(TAG, "body: ${response.body<String>()}")
client.close()
}