mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[starter][driver] Provide method to perform transform on "raw" data instead of metric
From CSV/JSON meter we often get ns and convert to ms after that but ns doesn't fit into integer so we have to transform initial values and not converted ones GitOrigin-RevId: ee2c237ec3b67e39df49a0654189926eda4f5abc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
95af4ec008
commit
675565645b
@@ -13,8 +13,10 @@ import kotlin.io.path.name
|
||||
* [metersFilter] Input data: key - meter name. value - list of collected data points for that meter
|
||||
*/
|
||||
@Deprecated("Use com.intellij.tools.ide.metrics.collector.OpenTelemetryJsonMeterCollector")
|
||||
open class OpenTelemetryCsvMeterCollector(val metricsSelectionStrategy: MetricsSelectionStrategy,
|
||||
val metersFilter: (Map.Entry<String, List<LongPointData>>) -> Boolean) : TelemetryMetricsCollector {
|
||||
open class OpenTelemetryCsvMeterCollector(
|
||||
val metricsSelectionStrategy: MetricsSelectionStrategy,
|
||||
val metersFilter: (Map.Entry<String, List<LongPointData>>) -> Boolean,
|
||||
) : TelemetryMetricsCollector {
|
||||
private fun getOpenTelemetryCsvReportFiles(logsDirPath: Path): List<Path> {
|
||||
val metricsCsvFiles = logsDirPath.listDirectoryEntries("*.csv").filter { it.name.startsWith("open-telemetry-metrics") }
|
||||
require(metricsCsvFiles.isNotEmpty()) {
|
||||
@@ -24,16 +26,16 @@ open class OpenTelemetryCsvMeterCollector(val metricsSelectionStrategy: MetricsS
|
||||
return metricsCsvFiles
|
||||
}
|
||||
|
||||
private fun convertLongPointDataToIJPerfMetric(metricName: String, metricData: LongPointData): PerformanceMetrics.Metric {
|
||||
return PerformanceMetrics.newDuration(metricName, metricData.value.toInt())
|
||||
}
|
||||
|
||||
override fun collect(logsDirPath: Path): List<PerformanceMetrics.Metric> {
|
||||
fun collect(logsDirPath: Path, transform: (Map.Entry<String, LongPointData>) -> Pair<String, Int>): List<PerformanceMetrics.Metric> {
|
||||
val telemetryMetrics: Map<String, LongPointData> =
|
||||
MetricsImporterUtils.fromCsvFile(getOpenTelemetryCsvReportFiles(logsDirPath))
|
||||
.filter(metersFilter)
|
||||
.map { it.key to metricsSelectionStrategy.selectMetric(it.value) }.toMap()
|
||||
|
||||
return telemetryMetrics.map { convertLongPointDataToIJPerfMetric(metricName = it.key, metricData = it.value) }
|
||||
return telemetryMetrics.map { transform(it) }.map { PerformanceMetrics.newDuration(name = it.first, durationMillis = it.second) }
|
||||
}
|
||||
|
||||
override fun collect(logsDirPath: Path): List<PerformanceMetrics.Metric> {
|
||||
return collect(logsDirPath) { it.key to it.value.value.toInt() }
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.intellij.tools.ide.metrics.collector.metrics.PerformanceMetrics
|
||||
import com.intellij.tools.ide.util.common.logError
|
||||
import io.opentelemetry.sdk.common.InstrumentationScopeInfo
|
||||
import io.opentelemetry.sdk.metrics.data.Data
|
||||
import io.opentelemetry.sdk.metrics.data.LongPointData
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData
|
||||
import io.opentelemetry.sdk.metrics.data.MetricDataType
|
||||
import io.opentelemetry.sdk.resources.Resource
|
||||
@@ -22,7 +23,7 @@ import kotlin.io.path.name
|
||||
open class OpenTelemetryJsonMeterCollector(val metricsSelectionStrategy: MetricsSelectionStrategy,
|
||||
val meterFilter: (MetricData) -> Boolean) : TelemetryMetricsCollector {
|
||||
|
||||
override fun collect(logsDirPath: Path): List<PerformanceMetrics.Metric> {
|
||||
fun collect(logsDirPath: Path, transform: (Map. Entry<String, LongPointData>) -> Pair<String, Int>): List<PerformanceMetrics.Metric> {
|
||||
val metricsFiles = logsDirPath.listDirectoryEntries("*.json").filter { it.name.startsWith("open-telemetry-meter") }
|
||||
|
||||
// fallback to the collecting meters from the .csv files for older IDEs versions (where meters aren't exported to JSON files)
|
||||
@@ -43,9 +44,8 @@ open class OpenTelemetryJsonMeterCollector(val metricsSelectionStrategy: Metrics
|
||||
}
|
||||
|
||||
meterFilter(metricData)
|
||||
}.collect(logsDirPath)
|
||||
}.collect(logsDirPath, transform)
|
||||
}
|
||||
|
||||
val telemetryMetrics: List<MetricData> = metricsFiles.flatMap { OpenTelemetryMetersJsonImporter.fromJsonFile(it) }
|
||||
.filter(meterFilter)
|
||||
|
||||
@@ -63,4 +63,9 @@ open class OpenTelemetryJsonMeterCollector(val metricsSelectionStrategy: Metrics
|
||||
}.convert(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun collect(logsDirPath: Path): List<PerformanceMetrics.Metric> {
|
||||
return collect(logsDirPath) { it.key to it.value.value.toInt() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user