org.elasticsearch.telemetry.Measurement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of framework Show documentation
Show all versions of framework Show documentation
Elasticsearch subproject :test:framework
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
package org.elasticsearch.telemetry;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* A single measurement from an {@link org.elasticsearch.telemetry.metric.Instrument}.
*/
public record Measurement(Number value, Map attributes, boolean isDouble) {
public Measurement {
Objects.requireNonNull(value);
}
public boolean isLong() {
return isDouble == false;
}
public double getDouble() {
assert isDouble;
return value.doubleValue();
}
public long getLong() {
assert isLong();
return value.longValue();
}
/**
* Add measurements with the same attributes together. All measurements must be from the
* same instrument. If some measurements differ on {@link #isDouble}, @throws IllegalArgumentException
*/
public static List combine(List measurements) {
if (measurements == null || measurements.isEmpty()) {
return Collections.emptyList();
}
boolean isDouble = measurements.get(0).isDouble;
Map