Skip to content

Commit

Permalink
Merge pull request #2184 from DataDog/yl/metric-benchmark-fix
Browse files Browse the repository at this point in the history
Clean up benchmark tool and application code
  • Loading branch information
ambushwork authored Aug 13, 2024
2 parents 84541d2 + c349c5e commit 2ea9e5e
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ fun ApplicationDefaultConfig.configureFlavorForBenchmark(
val config = sampleAppConfig("${rootDir.absolutePath}/config/benchmark.json")
buildConfigField(
"String",
"BM_RUM_APPLICATION_ID",
"BENCHMARK_RUM_APPLICATION_ID",
"\"${config.rumApplicationId}\""
)
buildConfigField(
"String",
"BM_CLIENT_TOKEN",
"BENCHMARK_CLIENT_TOKEN",
"\"${config.token}\""
)
buildConfigField(
"String",
"BM_API_KEY",
"BENCHMARK_API_KEY",
"\"${config.apiKey}\""
)
buildConfigField(
"String",
"BM_APPLICATION_KEY",
"BENCHMARK_APPLICATION_KEY",
"\"${config.applicationKey}\""
)
}
Expand Down
4 changes: 2 additions & 2 deletions sample/benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Ddsdkandroid">
android:theme="@style/Theme.BenchmarkApp">
<activity
android:name="com.datadog.benchmark.sample.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Ddsdkandroid">
android:theme="@style/Theme.BenchmarkApp">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class BenchmarkApplication : Application() {
}

private fun createRumConfiguration(): RumConfiguration {
return RumConfiguration.Builder(BuildConfig.BM_RUM_APPLICATION_ID)
return RumConfiguration.Builder(BuildConfig.BENCHMARK_RUM_APPLICATION_ID)
.useViewTrackingStrategy(
NavigationViewTrackingStrategy(
R.id.nav_host_fragment,
Expand Down Expand Up @@ -78,7 +78,7 @@ internal class BenchmarkApplication : Application() {
@SuppressLint("LogNotTimber")
private fun createDatadogConfiguration(): Configuration {
val configBuilder = Configuration.Builder(
clientToken = BuildConfig.BM_CLIENT_TOKEN,
clientToken = BuildConfig.BENCHMARK_CLIENT_TOKEN,
env = BuildConfig.BUILD_TYPE
)
.setBatchSize(BatchSize.SMALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.datadog.sample.benchmark.BuildConfig
internal class DatadogBenchmark(config: Config) {

private var meter: DatadogMeter = DatadogMeter.create(
DatadogExporterConfiguration.Builder(BuildConfig.BM_API_KEY)
DatadogExporterConfiguration.Builder(BuildConfig.BENCHMARK_API_KEY)
.setApplicationId(BuildConfig.APPLICATION_ID)
.setApplicationName(BENCHMARK_APPLICATION_NAME)
.setRun(config.getRun())
Expand Down
2 changes: 1 addition & 1 deletion sample/benchmark/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Ddsdkandroid" parent="Theme.MaterialComponents.Light.DarkActionBar" />
<style name="Theme.BenchmarkApp" parent="Theme.MaterialComponents.Light.DarkActionBar" />
</resources>
7 changes: 2 additions & 5 deletions tools/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ dependencies {

implementation(libs.kotlin)
implementation(libs.okHttp)
api(libs.openTelemetryApiBenchmark)
api(libs.openTelemetrySdkBenchmark)
implementation(libs.openTelemetryApiBenchmark)
implementation(libs.openTelemetrySdkBenchmark)
implementation(libs.gson)
compileOnly(libs.detektApi)
testImplementation(project(":tools:unit")) {
attributes {
attribute(
Expand All @@ -46,8 +45,6 @@ dependencies {

testImplementation(libs.bundles.jUnit5)
testImplementation(libs.bundles.testTools)
testImplementation(libs.detektTest)
testImplementation(libs.robolectric)
}

kotlinConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ enum class EndPoint(
metrics = "https://api.datadoghq.eu/",
traces = "https://public-trace-http-intake.logs.datadoghq.eu/"
),
US1_FED(
metrics = "https://api.ddog-gov.com/",
traces = "https://trace.browser-intake-ddog-gov.com/"
AP1(
metrics = "https://ap1.datadoghq.com",
traces = "https://browser-intake-ap1-datadoghq.com"
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.opentelemetry.sdk.metrics.data.AggregationTemporality
import io.opentelemetry.sdk.metrics.data.MetricData
import io.opentelemetry.sdk.metrics.export.MetricExporter

internal class LogsMetricExporter(datadogExporterConfiguration: DatadogExporterConfiguration) : MetricExporter {
internal class LogcatMetricExporter(datadogExporterConfiguration: DatadogExporterConfiguration) : MetricExporter {

private val metricContext: MetricContext = MetricContext(
deviceModel = Build.MODEL,
Expand All @@ -33,14 +33,10 @@ internal class LogsMetricExporter(datadogExporterConfiguration: DatadogExporterC
}

override fun export(metrics: Collection<MetricData>): CompletableResultCode {
print(metrics)
return CompletableResultCode.ofSuccess()
}

private fun print(metrics: Collection<MetricData>) {
MetricRequestBodyBuilder(metricContext).buildJsonElement(metrics.toList()).toString().apply {
Log.i("LogsMetricExporter", this)
}
return CompletableResultCode.ofSuccess()
}

override fun flush(): CompletableResultCode {
Expand Down
91 changes: 0 additions & 91 deletions tools/benchmark/src/main/java/com/datadog/benchmark/ext/FileExt.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

package com.datadog.benchmark.internal.reader

import com.datadog.benchmark.ext.canReadSafe
import com.datadog.benchmark.ext.existsSafe
import com.datadog.benchmark.ext.readTextSafe
import java.io.File

/**
Expand All @@ -23,11 +20,11 @@ internal class CPUVitalReader(

@Suppress("ReturnCount")
override fun readVitalData(): Double? {
if (!(statFile.existsSafe() && statFile.canReadSafe())) {
if (!(statFile.exists() && statFile.canRead())) {
return null
}

val stat = statFile.readTextSafe() ?: return null
val stat = statFile.readText()
val tokens = stat.split(' ')
val utime = if (tokens.size > UTIME_IDX) {
tokens[UTIME_IDX].toLong()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

package com.datadog.benchmark.internal.reader

import com.datadog.benchmark.ext.canReadSafe
import com.datadog.benchmark.ext.existsSafe
import com.datadog.benchmark.ext.readLinesSafe
import java.io.File

/**
Expand All @@ -20,16 +17,13 @@ internal class MemoryVitalReader(
) : VitalReader {

override fun readVitalData(): Double? {
if (!(statusFile.existsSafe() && statusFile.canReadSafe())) {
if (!(statusFile.exists() && statusFile.canRead())) {
return null
}

val memorySizeKb = statusFile.readLinesSafe()
?.mapNotNull { line ->
VM_RSS_REGEX.matchEntire(line)?.groupValues?.getOrNull(1)
}
?.firstOrNull()
?.toDoubleOrNull()
val memorySizeKb = statusFile.readLines().firstNotNullOfOrNull { line ->
VM_RSS_REGEX.matchEntire(line)?.groupValues?.getOrNull(1)
}?.toDoubleOrNull()

return if (memorySizeKb == null) {
null
Expand Down

0 comments on commit 2ea9e5e

Please sign in to comment.