Skip to content

Commit

Permalink
修复CI问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chengyouling committed Nov 7, 2024
1 parent 1148a90 commit 5944b89
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/actions/common/mq-grayscale/rocketmq/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ runs:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/rocketmq-grayscale/common
log-dir: ./logs/rocketmq-grayscale/common
2 changes: 1 addition & 1 deletion .github/actions/common/plugin-change-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ runs:
${{ steps.changed-common-action.outputs.changed }} == 'true' -o ${{ env.triggerPushEvent }} == 'true' ];then
echo "enableXdsServicAction=true" >> $GITHUB_ENV
fi
# ==========mq grayscale rocketmq is needed to test?==========
if [ ${{ env.mqGrayscaleRocketMqChanged }} == 'true' -o \
${{ env.sermantAgentCoreChanged }} == 'true' -o \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/message_gray_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ jobs:
- name: common operations
uses: ./.github/actions/common/mq-grayscale/rocketmq
- name: message gray test for test-model=${{ matrix.test-model }} rocketMqClientVersion=${{ matrix.rocketMqClientVersion }}
uses: ./.github/actions/scenarios/mq-grayscale/rocketmq
uses: ./.github/actions/scenarios/mq-grayscale/rocketmq
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@

package io.sermant.demo.grayscale.rocketmq.consumer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.PullStatus;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.impl.consumer.PullResultExt;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* consumer controller
*
Expand All @@ -52,33 +55,40 @@ public class RocketMqConsumerController {
@Value("${rocketmq.topic}")
private String topic;

@GetMapping("/getMessageCount")
public Map<String, Object> getMessageCount() {
return RocketMqMessageUtils.getMessageCount();
}

/**
* clear cache count info
*
* @return is success
*/
@GetMapping("/clearMessageCount")
public String clearMessageCount() {
RocketMqMessageUtils.clearMessageCount();
return "success";
}

@GetMapping("/consumePullMessage")
public Map<String, Object> consumePullMessage() {
/**
* pull message
*
* @return message count
*/
@GetMapping("/getMessageCount")
public Map<String, Object> getMessageCount() {
try {
if (pullConsumer == null) {
pullConsumer = new DefaultMQPullConsumer("default");
pullConsumer.setNamesrvAddr(nameServer);
pullConsumer.setMaxReconsumeTimes(10000);
int maxReconsumeTimes = 10000;

Check failure on line 80 in sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-consumer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/consumer/RocketMqConsumerController.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 '10000' is a magic number. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-consumer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/consumer/RocketMqConsumerController.java:80:41: error: '10000' is a magic number. (com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck)
pullConsumer.setMaxReconsumeTimes(maxReconsumeTimes);
pullConsumer.start();
}
Set<MessageQueue> MessageQueues = pullConsumer.fetchSubscribeMessageQueues(topic);
if (MessageQueues.isEmpty()) {
Set<MessageQueue> messageQueues = pullConsumer.fetchSubscribeMessageQueues(topic);
if (messageQueues.isEmpty()) {
return new HashMap<>();
}
for (MessageQueue mq : MessageQueues) {
int maxNums = 32;

Check failure on line 88 in sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-consumer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/consumer/RocketMqConsumerController.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 '32' is a magic number. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-consumer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/consumer/RocketMqConsumerController.java:88:27: error: '32' is a magic number. (com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck)
for (MessageQueue mq : messageQueues) {
PullResultExt pullResult = (PullResultExt) pullConsumer.pullBlockIfNotFound(mq, null,
getMessageQueueOffSet(mq), 32);
getMessageQueueOffSet(mq), maxNums);
putMessageQueueOffSet(mq, pullResult);
if (PullStatus.FOUND == pullResult.getPullStatus()) {

Check warning on line 93 in sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-consumer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/consumer/RocketMqConsumerController.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议8.2.3 表达式的比较,应当遵循左侧倾向于变化、右侧倾向于不变的原则。 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-consumer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/consumer/RocketMqConsumerController.java:93:0: warning: 编程规范-建议8.2.3 表达式的比较,应当遵循左侧倾向于变化、右侧倾向于不变的原则。 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck)
List<MessageExt> messageExts = pullResult.getMsgFoundList();
Expand All @@ -88,7 +98,7 @@ public Map<String, Object> consumePullMessage() {
}
}
return RocketMqMessageUtils.getMessageCount();
} catch (Exception e) {
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
LOGGER.error("consumePullMessage error!", e);
return new HashMap<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package io.sermant.demo.grayscale.rocketmq.consumer;

import org.apache.rocketmq.common.message.MessageExt;

import java.util.HashMap;
import java.util.Map;

import org.apache.rocketmq.common.message.MessageExt;

/**
* message count utils
*
Expand All @@ -34,6 +34,9 @@ public class RocketMqMessageUtils {

private static int baseMessageCount = 0;

private RocketMqMessageUtils() {
}

public static void convertMessageCount(MessageExt messageExt) {

Check failure on line 40 in sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-consumer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/consumer/RocketMqMessageUtils.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-consumer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/consumer/RocketMqMessageUtils.java:40:5: error: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
if (messageExt.getProperties() != null && GRAY.equals(messageExt.getProperties().get(
"x_lane_canary"))) {
Expand All @@ -43,12 +46,21 @@ public static void convertMessageCount(MessageExt messageExt) {
baseMessageCount++;
}

/**
* get base/gray message count
*
* @return message count
*/
public static Map<String, Object> getMessageCount() {
Map<String, Object> countMap = new HashMap<>();
countMap.put("baseMessageCount", baseMessageCount);
countMap.put("grayMessageCount", grayMessageCount);
return countMap;
}

/**
* clear cache count info
*/
public static void clearMessageCount() {
baseMessageCount = 0;
grayMessageCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ management:
endpoints:
web:
exposure:
include: "*"
include: "*"
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ public void testBaseBaseGrayExcGrayConsumeMessage() {
}

private String getBaseResult() {
return restTemplate.getForObject("http://127.0.0.1:9000/consumePullMessage", String.class);
return restTemplate.getForObject("http://127.0.0.1:9000/getMessageCount", String.class);
}

private String getGrayResult() {
return restTemplate.getForObject("http://127.0.0.1:9010/consumePullMessage", String.class);
return restTemplate.getForObject("http://127.0.0.1:9010/getMessageCount", String.class);
}

private void producerMessage() {
Expand All @@ -152,12 +152,12 @@ private void producerMessage() {
private void triggerAndClearCacheCount(boolean isGrayInstanceInit) {
if (isGrayInstanceInit) {
// Trigger start gray consumer.
restTemplate.getForObject("http://127.0.0.1:9010/consumePullMessage", String.class);
restTemplate.getForObject("http://127.0.0.1:9010/getMessageCount", String.class);
restTemplate.getForObject("http://127.0.0.1:9010/clearMessageCount", String.class);
}

// Trigger start base consumer.
restTemplate.getForObject("http://127.0.0.1:9000/consumePullMessage", String.class);
restTemplate.getForObject("http://127.0.0.1:9000/getMessageCount", String.class);
restTemplate.getForObject("http://127.0.0.1:9000/clearMessageCount", String.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@

package io.sermant.demo.grayscale.rocketmq.producer;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;

/**
* producer controller
*
Expand All @@ -33,31 +38,38 @@
*/
@RestController
public class MqProducerController {
private static final Logger LOGGER = LoggerFactory.getLogger(MqProducerController.class);
private static final Logger LOGGER = LoggerFactory.getLogger(MqProducerController.class);

@Value("${rocketmq.address}")
private String mqAddress;
@Value("${rocketmq.address}")
private String mqAddress;

@Value("${rocketmq.topic}")
private String mqTopic;
@Value("${rocketmq.topic}")
private String mqTopic;

private DefaultMQProducer defaultMQProducer;
private DefaultMQProducer defaultMqProducer;

/**
* producer message
*
* @param message message
* @return is success
*/
@GetMapping("/producerMessage")

Check failure on line 57 in sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-producer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/producer/MqProducerController.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 'method def modifier' has incorrect indentation level 2, expected level should be 4. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-producer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/producer/MqProducerController.java:57:3: error: 'method def modifier' has incorrect indentation level 2, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
public String producerMessage(@RequestParam("message") String message) {
try {
if (defaultMQProducer == null) {
defaultMQProducer = new DefaultMQProducer("default");
defaultMQProducer.setNamesrvAddr(mqAddress);
defaultMQProducer.setSendMsgTimeout(60000);
defaultMQProducer.start();
}
Message mqMessage = new Message(mqTopic, message.getBytes());
defaultMQProducer.send(mqMessage);
} catch (Exception e) {
LOGGER.error("send message error, address={}, message={}", mqAddress, message, e);
return "error";
public String producerMessage(@RequestParam("message") String message) {
try {
if (defaultMqProducer == null) {
int sendMsgTimeout = 60000;

Check failure on line 61 in sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-producer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/producer/MqProducerController.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 '60000' is a magic number. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-integration-tests/mq-grayscale-rocketmq-test/grayscale-rocketmq-producer-demo/src/main/java/io/sermant/demo/grayscale/rocketmq/producer/MqProducerController.java:61:38: error: '60000' is a magic number. (com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck)
defaultMqProducer = new DefaultMQProducer("default");
defaultMqProducer.setNamesrvAddr(mqAddress);
defaultMqProducer.setSendMsgTimeout(sendMsgTimeout);
defaultMqProducer.start();
}
Message mqMessage = new Message(mqTopic, message.getBytes(StandardCharsets.UTF_8));
defaultMqProducer.send(mqMessage);
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
LOGGER.error("send message error, address={}, message={}", mqAddress, message, e);
return "error";
}
return "success";
}
return "success";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ management:
endpoints:
web:
exposure:
include: "*"
include: "*"
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@
<module>grayscale-rocketmq-producer-demo</module>
<module>grayscale-rocketmq-consumer-demo</module>
</modules>

</project>

0 comments on commit 5944b89

Please sign in to comment.