forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LegacyStatCounter and LegacyStatTimer
- Also migrate GatewayReceiverStats events received to use new LegacyStatCounter. Co-authored-by: Kirk Lund <[email protected]>
- Loading branch information
1 parent
51da276
commit a483562
Showing
15 changed files
with
1,590 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ore/src/main/java/org/apache/geode/internal/statistics/meters/DoubleStatisticBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work for additional information regarding | ||
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package org.apache.geode.internal.statistics.meters; | ||
|
||
import org.apache.geode.Statistics; | ||
|
||
/** | ||
* Increments and reads a {@code double} stat. | ||
*/ | ||
public class DoubleStatisticBinding implements StatisticBinding { | ||
private final Statistics statistics; | ||
private final int statId; | ||
|
||
public DoubleStatisticBinding(Statistics statistics, int statId) { | ||
this.statistics = statistics; | ||
this.statId = statId; | ||
} | ||
|
||
@Override | ||
public void add(double amount) { | ||
statistics.incDouble(statId, amount); | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return statistics.getDouble(statId); | ||
} | ||
|
||
@Override | ||
public long longValue() { | ||
return (long) statistics.getDouble(statId); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...e-core/src/main/java/org/apache/geode/internal/statistics/meters/IntStatisticBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work for additional information regarding | ||
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package org.apache.geode.internal.statistics.meters; | ||
|
||
import org.apache.geode.Statistics; | ||
|
||
/** | ||
* Increments and reads an {@code int} stat. | ||
*/ | ||
public class IntStatisticBinding implements StatisticBinding { | ||
private final Statistics statistics; | ||
private final int statId; | ||
|
||
public IntStatisticBinding(Statistics statistics, int statId) { | ||
this.statistics = statistics; | ||
this.statId = statId; | ||
} | ||
|
||
@Override | ||
public void add(double amount) { | ||
statistics.incInt(statId, (int) amount); | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return (double) statistics.getInt(statId); | ||
} | ||
|
||
@Override | ||
public long longValue() { | ||
return 0; | ||
} | ||
} |
154 changes: 154 additions & 0 deletions
154
geode-core/src/main/java/org/apache/geode/internal/statistics/meters/LegacyStatCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work for additional information regarding | ||
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package org.apache.geode.internal.statistics.meters; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tag; | ||
|
||
import org.apache.geode.Statistics; | ||
|
||
/** | ||
* Wraps a {@code Counter} to increment and read an associated stat as well as incrementing the | ||
* counter. | ||
*/ | ||
public class LegacyStatCounter implements Counter { | ||
private final Counter underlyingCounter; | ||
private final StatisticBinding statisticBinding; | ||
|
||
/** | ||
* Creates a {@code LegacyStatCounter} that wraps the given counter to add the ability | ||
* to increment and read an associated stat. | ||
* | ||
* @param underlyingCounter the counter to wrap | ||
* @param statisticBinding associates the {@code LegacyStatCounter} with a stat | ||
*/ | ||
private LegacyStatCounter(Counter underlyingCounter, | ||
StatisticBinding statisticBinding) { | ||
this.underlyingCounter = underlyingCounter; | ||
this.statisticBinding = statisticBinding; | ||
} | ||
|
||
/** | ||
* Increments both the underlying counter and the associated stat by the given amount. | ||
*/ | ||
@Override | ||
public void increment(double amount) { | ||
underlyingCounter.increment(amount); | ||
statisticBinding.add(amount); | ||
} | ||
|
||
/** | ||
* Returns the value of the associated stat. | ||
*/ | ||
@Override | ||
public double count() { | ||
return statisticBinding.doubleValue(); | ||
} | ||
|
||
/** | ||
* Returns the ID of the underlying counter. | ||
*/ | ||
@Override | ||
public Id getId() { | ||
return underlyingCounter.getId(); | ||
} | ||
|
||
/** | ||
* Returns a builder that can associate a stat with the eventual {@code LegacyStatCounter}. To | ||
* associate the counter with a stat, call one of | ||
* {@link Builder#doubleStatistic(Statistics, int)} or | ||
* {@link Builder#longStatistic(Statistics, int)}. | ||
*/ | ||
public static Builder builder(String name) { | ||
return new Builder(name); | ||
} | ||
|
||
public static class Builder { | ||
private final Counter.Builder builder; | ||
private StatisticBinding statisticBinding = StatisticBinding.noOp(); | ||
|
||
private Builder(String name) { | ||
builder = Counter.builder(name); | ||
} | ||
|
||
/** | ||
* Prepares to associate the eventual {@code LegacyStatCounter} with the specified {@code | ||
* double} stat. The given {@code Statistics} and {@code statId} must identify a {@code | ||
* double} stat. | ||
*/ | ||
public Builder doubleStatistic(Statistics statistics, int statId) { | ||
statisticBinding = new DoubleStatisticBinding(statistics, statId); | ||
return this; | ||
} | ||
|
||
/** | ||
* Prepares to associate the eventual {@code LegacyStatCounter} with the specified {@code | ||
* int} stat. The given {@code Statistics} and {@code statId} must identify an {@code int} | ||
* stat. | ||
*/ | ||
public Builder intStatistic(Statistics statistics, int statId) { | ||
statisticBinding = new IntStatisticBinding(statistics, statId); | ||
return this; | ||
} | ||
|
||
/** | ||
* Prepares to associate the eventual {@code LegacyStatCounter} with the specified {@code | ||
* long} stat. The given {@code Statistics} and {@code statId} must identify a {@code long} | ||
* stat. | ||
*/ | ||
public Builder longStatistic(Statistics statistics, int statId) { | ||
statisticBinding = new LongStatisticBinding(statistics, statId); | ||
return this; | ||
} | ||
|
||
public Builder baseUnit(String unit) { | ||
builder.baseUnit(unit); | ||
return this; | ||
} | ||
|
||
public Builder description(String description) { | ||
builder.description(description); | ||
return this; | ||
} | ||
|
||
public Builder tag(String name, String value) { | ||
builder.tag(name, value); | ||
return this; | ||
} | ||
|
||
public Builder tags(String... tags) { | ||
builder.tags(tags); | ||
return this; | ||
} | ||
|
||
public Builder tags(Iterable<Tag> tags) { | ||
builder.tags(tags); | ||
return this; | ||
} | ||
|
||
/** | ||
* Registers a {@code Counter} with the given registry, and returns a {@code LegacyStatCounter} | ||
* that wraps the counter to increment and read the associated stat. Note that the returned | ||
* {@code LegacyStatCounter} is not registered with the registry, but it has the same ID, so | ||
* it can be used to remove the registered counter from the registry. | ||
*/ | ||
public LegacyStatCounter register(MeterRegistry registry) { | ||
Counter underlyingCounter = builder.register(registry); | ||
return new LegacyStatCounter(underlyingCounter, statisticBinding); | ||
} | ||
} | ||
} |
Oops, something went wrong.