Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.49.0</version>
<version>2.50.0</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
@StableApi
public class ExemplarSampler {

@SuppressWarnings("ReferenceEquality")
private static boolean sameObject(Object left, Object right) {
return left == right;
}

private final ExemplarSamplerConfig config;
private final Exemplar[] exemplars;
private final Exemplar[]
Expand Down Expand Up @@ -223,7 +228,7 @@ private long doObserveWithoutUpperBounds(double value) {
int oldestIndex = -1;
for (int i = 0; i < exemplars.length; i++) {
Exemplar exemplar = exemplars[i];
if (exemplar != null && exemplar != smallest && exemplar != largest) {
if (exemplar != null && !sameObject(exemplar, smallest) && !sameObject(exemplar, largest)) {
if (oldestTimestamp == 0 || exemplar.getTimestampMillis() < oldestTimestamp) {
oldestTimestamp = exemplar.getTimestampMillis();
oldestIndex = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
*/
final class CKMSQuantiles {

@SuppressWarnings("ReferenceEquality")
private static boolean sameObject(Object left, Object right) {
return left == right;
}

final Quantile[] quantiles;

/** Total number of observations (not including those that are still in the buffer). */
Expand Down Expand Up @@ -203,7 +208,7 @@ void compress() {
right = left;
left = descendingIterator.next();
r = r - left.g;
if (left == samples.getFirst()) {
if (sameObject(left, samples.getFirst())) {
// The min sample must never be merged.
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static String[] makePrometheusNames(String[] names) {
for (int i = 0; i < names.length; i++) {
String name = names[i];
if (!PrometheusNaming.isValidLegacyLabelName(name)) {
if (prometheusNames == names) {
if (sameObject(prometheusNames, names)) {
prometheusNames = Arrays.copyOf(names, names.length);
}
prometheusNames[i] = PrometheusNaming.prometheusName(name);
Expand Down Expand Up @@ -234,7 +234,8 @@ public Labels merge(Labels other) {
}
String[] names = new String[this.names.length + other.names.length];
String[] prometheusNames = names;
if (this.names != this.prometheusNames || other.names != other.prometheusNames) {
if (!sameObject(this.names, this.prometheusNames)
|| !sameObject(other.names, other.prometheusNames)) {
prometheusNames = new String[names.length];
}
String[] values = new String[names.length];
Expand All @@ -244,28 +245,28 @@ public Labels merge(Labels other) {
if (thisPos >= this.names.length) {
names[thisPos + otherPos] = other.names[otherPos];
values[thisPos + otherPos] = other.values[otherPos];
if (prometheusNames != names) {
if (!sameObject(prometheusNames, names)) {
prometheusNames[thisPos + otherPos] = other.prometheusNames[otherPos];
}
otherPos++;
} else if (otherPos >= other.names.length) {
names[thisPos + otherPos] = this.names[thisPos];
values[thisPos + otherPos] = this.values[thisPos];
if (prometheusNames != names) {
if (!sameObject(prometheusNames, names)) {
prometheusNames[thisPos + otherPos] = this.prometheusNames[thisPos];
}
thisPos++;
} else if (this.prometheusNames[thisPos].compareTo(other.prometheusNames[otherPos]) < 0) {
names[thisPos + otherPos] = this.names[thisPos];
values[thisPos + otherPos] = this.values[thisPos];
if (prometheusNames != names) {
if (!sameObject(prometheusNames, names)) {
prometheusNames[thisPos + otherPos] = this.prometheusNames[thisPos];
}
thisPos++;
} else if (this.prometheusNames[thisPos].compareTo(other.prometheusNames[otherPos]) > 0) {
names[thisPos + otherPos] = other.names[otherPos];
values[thisPos + otherPos] = other.values[otherPos];
if (prometheusNames != names) {
if (!sameObject(prometheusNames, names)) {
prometheusNames[thisPos + otherPos] = other.prometheusNames[otherPos];
}
otherPos++;
Expand Down Expand Up @@ -321,6 +322,11 @@ public int compareTo(Labels other) {
}

// Looks like Java doesn't have a compareTo() method for arrays.
@SuppressWarnings("ReferenceEquality")
private static boolean sameObject(Object left, Object right) {
return left == right;
}

private int compare(String[] array1, String[] array2) {
int result;
for (int i = 0; i < array1.length; i++) {
Expand Down Expand Up @@ -505,14 +511,14 @@ private static void insertionSort(
int j = i - 1;
while (j >= left && compare(prometheusNames[j], prometheusName) > 0) {
names[j + 1] = names[j];
if (prometheusNames != names) {
if (!sameObject(prometheusNames, names)) {
prometheusNames[j + 1] = prometheusNames[j];
}
values[j + 1] = values[j];
j--;
}
names[j + 1] = name;
if (prometheusNames != names) {
if (!sameObject(prometheusNames, names)) {
prometheusNames[j + 1] = prometheusName;
}
values[j + 1] = value;
Expand Down Expand Up @@ -594,7 +600,7 @@ private static void swap(
tmp = values[i];
values[i] = values[j];
values[j] = tmp;
if (prometheusNames != names) {
if (!sameObject(prometheusNames, names)) {
tmp = prometheusNames[i];
prometheusNames[i] = prometheusNames[j];
prometheusNames[j] = tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Quantiles implements Iterable<Quantile> {

private Quantiles(List<Quantile> quantiles) {
quantiles = new ArrayList<>(quantiles);
quantiles.sort(Comparator.comparing(Quantile::getQuantile));
quantiles.sort(Comparator.comparingDouble(Quantile::getQuantile));
this.quantiles = Collections.unmodifiableList(quantiles);
validate();
}
Expand Down