Skip to content

Commit

Permalink
Fixed issue with wrong parameter type (provectus#65)
Browse files Browse the repository at this point in the history
* Fixed issue with wrong parameter type

* Changed object to number

* Changede object to number jmx metrics

Co-authored-by: Roman Nedzvetskiy <roman@Romans-MacBook-Pro.local>
  • Loading branch information
yazebochan and Roman Nedzvetskiy committed Jun 25, 2020
1 parent 941f3b3 commit 814a744
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import com.provectus.kafka.ui.model.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ValueMapping;

import java.math.BigDecimal;

@Mapper(componentModel = "spring")
public interface ClusterMapper {
Expand All @@ -22,6 +23,10 @@ public interface ClusterMapper {
@Mapping(target = "bytesOutPerSec", source = "metrics.bytesOutPerSec")
Cluster toCluster(KafkaCluster cluster);

default BigDecimal map (Number number) {
return new BigDecimal(number.toString());
}

BrokersMetrics toBrokerMetrics(InternalClusterMetrics metrics);
Topic toTopic(InternalTopic topic);
TopicDetails toTopicDetails(InternalTopic topic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class InternalClusterMetrics {
private final int offlinePartitionCount;
private final int inSyncReplicasCount;
private final int outOfSyncReplicasCount;
private final Map<String, BigDecimal> bytesInPerSec;
private final Map<String, BigDecimal> bytesOutPerSec;
private final Map<String, Number> bytesInPerSec;
private final Map<String, Number> bytesOutPerSec;
private final int segmentCount;
private final long segmentSize;
private final Map<Integer, InternalBrokerMetrics> internalBrokerMetrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ public class JmxClusterUtil {

private static final List<String> attrNames = Arrays.asList("OneMinuteRate", "FiveMinuteRate", "FifteenMinuteRate");

public Map<String, BigDecimal> getJmxTrafficMetrics(int jmxPort, String jmxHost, String metricName) {
public Map<String, Number> getJmxTrafficMetrics(int jmxPort, String jmxHost, String metricName) {
String jmxUrl = JMX_URL + jmxHost + ":" + jmxPort + "/" + JMX_SERVICE_TYPE;
Map<String, BigDecimal> result = new HashMap<>();
Map<String, Number> result = new HashMap<>();
JMXConnector srv = null;
try {
srv = pool.borrowObject(jmxUrl);
MBeanServerConnection msc = srv.getMBeanServerConnection();
ObjectName name = metricName.equals(BYTES_IN_PER_SEC) ? new ObjectName(BYTES_IN_PER_SEC_MBEAN_OBJECT_NAME) :
new ObjectName(BYTES_OUT_PER_SEC_MBEAN_OBJECT_NAME);
for (String attrName : attrNames) {
result.put(attrName, BigDecimal.valueOf((Double) msc.getAttribute(name, attrName)));
Number value = (Number) msc.getAttribute(name, attrName);
result.put(attrName, value instanceof Double ? BigDecimal.valueOf((Double) value) : Integer.valueOf(value.toString()));
}
pool.returnObject(jmxUrl, srv);
} catch (MalformedURLException url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ private Mono<InternalClusterMetrics> getClusterMetrics(KafkaCluster cluster, Adm
c -> {
InternalClusterMetrics.InternalClusterMetricsBuilder metricsBuilder = InternalClusterMetrics.builder();
metricsBuilder.brokerCount(brokers.size()).activeControllers(c != null ? 1 : 0);
Map<String, BigDecimal> bytesInPerSec = jmxClusterUtil.getJmxTrafficMetrics(cluster.getJmxPort(), c.host(), JmxClusterUtil.BYTES_IN_PER_SEC);
Map<String, BigDecimal> bytesOutPerSec = jmxClusterUtil.getJmxTrafficMetrics(cluster.getJmxPort(), c.host(), JmxClusterUtil.BYTES_OUT_PER_SEC);
Map<String, Number> bytesInPerSec = jmxClusterUtil.getJmxTrafficMetrics(cluster.getJmxPort(), c.host(), JmxClusterUtil.BYTES_IN_PER_SEC);
Map<String, Number> bytesOutPerSec = jmxClusterUtil.getJmxTrafficMetrics(cluster.getJmxPort(), c.host(), JmxClusterUtil.BYTES_OUT_PER_SEC);
metricsBuilder
.internalBrokerMetrics((brokers.stream().map(Node::id).collect(Collectors.toMap(k -> k, v -> InternalBrokerMetrics.builder().build()))))
.bytesOutPerSec(bytesOutPerSec)
Expand Down

0 comments on commit 814a744

Please sign in to comment.