Skip to content

Commit

Permalink
Merge branch 'apache:develop' into develop2
Browse files Browse the repository at this point in the history
  • Loading branch information
yuz10 committed Jun 22, 2023
2 parents e8aa1f8 + 1f0cdc8 commit 38d15fd
Show file tree
Hide file tree
Showing 34 changed files with 1,840 additions and 648 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,9 @@ public void registerProcessor() {
*/
this.remotingServer.registerProcessor(RequestCode.ACK_MESSAGE, this.ackMessageProcessor, this.ackMessageExecutor);
this.fastRemotingServer.registerProcessor(RequestCode.ACK_MESSAGE, this.ackMessageProcessor, this.ackMessageExecutor);

this.remotingServer.registerProcessor(RequestCode.BATCH_ACK_MESSAGE, this.ackMessageProcessor, this.ackMessageExecutor);
this.fastRemotingServer.registerProcessor(RequestCode.BATCH_ACK_MESSAGE, this.ackMessageProcessor, this.ackMessageExecutor);
/**
* ChangeInvisibleTimeProcessor
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import io.opentelemetry.api.metrics.LongHistogram;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.metrics.ObservableLongGauge;
import io.opentelemetry.exporter.logging.LoggingMetricExporter;
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter;
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder;
import io.opentelemetry.exporter.prometheus.PrometheusHttpServer;
import io.opentelemetry.exporter.logging.LoggingMetricExporter;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.InstrumentSelector;
Expand All @@ -43,6 +43,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.broker.client.ConsumerManager;
Expand All @@ -61,11 +62,10 @@
import org.apache.rocketmq.common.topic.TopicValidator;
import org.apache.rocketmq.logging.org.slf4j.Logger;
import org.apache.rocketmq.logging.org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

import org.apache.rocketmq.remoting.metrics.RemotingMetricsManager;
import org.apache.rocketmq.remoting.protocol.header.SendMessageRequestHeader;
import org.apache.rocketmq.store.MessageStore;
import org.slf4j.bridge.SLF4JBridgeHandler;

import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.AGGREGATION_DELTA;
import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.COUNTER_CONSUMER_SEND_TO_DLQ_MESSAGES_TOTAL;
Expand Down Expand Up @@ -114,6 +114,8 @@ public class BrokerMetricsManager {
private LoggingMetricExporter loggingMetricExporter;
private Meter brokerMeter;

public static Supplier<AttributesBuilder> attributesBuilderSupplier = Attributes::builder;

// broker stats metrics
public static ObservableLongGauge processorWatermark = new NopObservableLongGauge();
public static ObservableLongGauge brokerPermission = new NopObservableLongGauge();
Expand Down Expand Up @@ -152,7 +154,11 @@ public BrokerMetricsManager(BrokerController brokerController) {
}

public static AttributesBuilder newAttributesBuilder() {
AttributesBuilder attributesBuilder = Attributes.builder();
AttributesBuilder attributesBuilder;
if (attributesBuilderSupplier == null) {
attributesBuilderSupplier = Attributes::builder;
}
attributesBuilder = attributesBuilderSupplier.get();
LABEL_MAP.forEach(attributesBuilder::put);
return attributesBuilder;
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,23 @@ public boolean addAk(int reviveQid, AckMsg ackMsg) {
return false;
}

int indexOfAck = point.indexOfAck(ackMsg.getAckOffset());
if (indexOfAck > -1) {
markBitCAS(pointWrapper.getBits(), indexOfAck);
if (ackMsg instanceof BatchAckMsg) {
for (Long ackOffset : ((BatchAckMsg) ackMsg).getAckOffsetList()) {
int indexOfAck = point.indexOfAck(ackOffset);
if (indexOfAck > -1) {
markBitCAS(pointWrapper.getBits(), indexOfAck);
} else {
POP_LOGGER.error("[PopBuffer]Invalid index of ack, reviveQid={}, {}, {}", reviveQid, ackMsg, point);
}
}
} else {
POP_LOGGER.error("[PopBuffer]Invalid index of ack, reviveQid={}, {}, {}", reviveQid, ackMsg, point);
return true;
int indexOfAck = point.indexOfAck(ackMsg.getAckOffset());
if (indexOfAck > -1) {
markBitCAS(pointWrapper.getBits(), indexOfAck);
} else {
POP_LOGGER.error("[PopBuffer]Invalid index of ack, reviveQid={}, {}, {}", reviveQid, ackMsg, point);
return true;
}
}

if (brokerController.getBrokerConfig().isEnablePopLog()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
*/
package org.apache.rocketmq.broker.processor;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.common.Pair;
import org.apache.rocketmq.common.constant.LoggerName;
import org.apache.rocketmq.logging.org.slf4j.Logger;
import org.apache.rocketmq.logging.org.slf4j.LoggerFactory;
import org.apache.rocketmq.remoting.protocol.header.ExtraInfoUtil;
import org.apache.rocketmq.store.pop.PopCheckPoint;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

public class PopInflightMessageCounter {
private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME);

Expand Down Expand Up @@ -61,26 +61,24 @@ public void incrementInFlightMessageNum(String topic, String group, int queueId,
});
}

public void decrementInFlightMessageNum(String topic, String group, String ckInfo) {
String[] ckInfoList = ExtraInfoUtil.split(ckInfo);
long popTime = ExtraInfoUtil.getPopTime(ckInfoList);
public void decrementInFlightMessageNum(String topic, String group, long popTime, int qId, int delta) {
if (popTime < this.brokerController.getShouldStartTime()) {
return;
}
decrementInFlightMessageNum(topic, group, ExtraInfoUtil.getQueueId(ckInfoList));
decrementInFlightMessageNum(topic, group, qId, delta);
}

public void decrementInFlightMessageNum(PopCheckPoint checkPoint) {
if (checkPoint.getPopTime() < this.brokerController.getShouldStartTime()) {
return;
}
decrementInFlightMessageNum(checkPoint.getTopic(), checkPoint.getCId(), checkPoint.getQueueId());
decrementInFlightMessageNum(checkPoint.getTopic(), checkPoint.getCId(), checkPoint.getQueueId(), 1);
}

public void decrementInFlightMessageNum(String topic, String group, int queueId) {
private void decrementInFlightMessageNum(String topic, String group, int queueId, int delta) {
topicInFlightMessageNum.computeIfPresent(buildKey(topic, group), (key, queueNum) -> {
queueNum.computeIfPresent(queueId, (queueIdKey, counter) -> {
if (counter.decrementAndGet() <= 0) {
if (counter.addAndGet(-delta) <= 0) {
return null;
}
return counter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.rocketmq.broker.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class BrokerMetricsManagerTest {

@Test
public void testNewAttributesBuilder() {
Attributes attributes = BrokerMetricsManager.newAttributesBuilder().put("a", "b")
.build();
assertThat(attributes.get(AttributeKey.stringKey("a"))).isEqualTo("b");
}

@Test
public void testCustomizedAttributesBuilder() {
BrokerMetricsManager.attributesBuilderSupplier = () -> new AttributesBuilder() {
private AttributesBuilder attributesBuilder = Attributes.builder();
@Override
public Attributes build() {
return attributesBuilder.put("customized", "value").build();
}

@Override
public <T> AttributesBuilder put(AttributeKey<Long> key, int value) {
attributesBuilder.put(key, value);
return this;
}

@Override
public <T> AttributesBuilder put(AttributeKey<T> key, T value) {
attributesBuilder.put(key, value);
return this;
}

@Override
public AttributesBuilder putAll(Attributes attributes) {
attributesBuilder.putAll(attributes);
return this;
}
};
Attributes attributes = BrokerMetricsManager.newAttributesBuilder().put("a", "b")
.build();
assertThat(attributes.get(AttributeKey.stringKey("a"))).isEqualTo("b");
assertThat(attributes.get(AttributeKey.stringKey("customized"))).isEqualTo("value");
}
}
Loading

0 comments on commit 38d15fd

Please sign in to comment.