Search in sources :

Example 6 with MetricsReader

use of org.apache.beam.sdk.testutils.metrics.MetricsReader in project beam by apache.

the class TextIOIT method fillMetricSuppliers.

private Set<Function<MetricsReader, NamedTestResult>> fillMetricSuppliers(String uuid, String timestamp) {
    Set<Function<MetricsReader, NamedTestResult>> metricSuppliers = new HashSet<>();
    metricSuppliers.add((reader) -> {
        long writeStartTime = reader.getStartTimeMetric("startTime");
        long writeEndTime = reader.getEndTimeMetric("middleTime");
        double writeTime = (writeEndTime - writeStartTime) / 1e3;
        return NamedTestResult.create(uuid, timestamp, "write_time", writeTime);
    });
    metricSuppliers.add((reader) -> {
        long readStartTime = reader.getStartTimeMetric("middleTime");
        long readEndTime = reader.getEndTimeMetric("endTime");
        double readTime = (readEndTime - readStartTime) / 1e3;
        return NamedTestResult.create(uuid, timestamp, "read_time", readTime);
    });
    metricSuppliers.add((reader) -> {
        long writeStartTime = reader.getStartTimeMetric("startTime");
        long readEndTime = reader.getEndTimeMetric("endTime");
        double runTime = (readEndTime - writeStartTime) / 1e3;
        return NamedTestResult.create(uuid, timestamp, "run_time", runTime);
    });
    if (datasetSize != null) {
        metricSuppliers.add((ignored) -> NamedTestResult.create(uuid, timestamp, "dataset_size", datasetSize));
    }
    if (gatherGcsPerformanceMetrics) {
        metricSuppliers.add(reader -> {
            MetricsReader actualReader = reader.withNamespace("org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystem");
            long numCopies = actualReader.getCounterMetric("num_copies");
            long copyTimeMsec = actualReader.getCounterMetric("copy_time_msec");
            double copiesPerSec = (numCopies < 0 || copyTimeMsec < 0) ? -1 : numCopies / (copyTimeMsec / 1e3);
            return NamedTestResult.create(uuid, timestamp, "copies_per_sec", copiesPerSec);
        });
    }
    return metricSuppliers;
}
Also used : Function(java.util.function.Function) MetricsReader(org.apache.beam.sdk.testutils.metrics.MetricsReader) HashSet(java.util.HashSet)

Aggregations

MetricsReader (org.apache.beam.sdk.testutils.metrics.MetricsReader)6 NamedTestResult (org.apache.beam.sdk.testutils.NamedTestResult)3 IOException (java.io.IOException)2 PipelineResult (org.apache.beam.sdk.PipelineResult)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 Duration (org.joda.time.Duration)2 Timestamp (com.google.cloud.Timestamp)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Read (org.apache.beam.sdk.io.Read)1 HashingFn (org.apache.beam.sdk.io.common.HashingFn)1 IOITHelper (org.apache.beam.sdk.io.common.IOITHelper)1 IOTestPipelineOptions (org.apache.beam.sdk.io.common.IOTestPipelineOptions)1 SyntheticBoundedSource (org.apache.beam.sdk.io.synthetic.SyntheticBoundedSource)1