Skip to content

Conversation

zhengyangyong
Copy link

@zhengyangyong zhengyangyong commented Nov 24, 2017

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 86.893% when pulling dfdf4e0 on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 86.91% when pulling 2c41cbd on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

@WillemJiang WillemJiang changed the title Jav 526 JAV-526 Writing metric data into files Nov 24, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 86.933% when pulling e4482cb on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

public static final String METRICS_POLL_TIME = "servicecomb.metrics.polltime";
public static final String METRICS_FILE_ENABLED = "servicecomb.metrics.file.enabled";
public static final String METRICS_FILE_PATH = "servicecomb.metrics.file.file_root_path";
public static final String METRICS_FILE_SIZE = "servicecomb.metrics.file.max_rolling_size";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant variable should be meaningful, Please add the important information about "rolling" to the constant.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

public static final String METRICS_FILE_ENABLED = "servicecomb.metrics.file.enabled";
public static final String METRICS_FILE_PATH = "servicecomb.metrics.file.file_root_path";
public static final String METRICS_FILE_SIZE = "servicecomb.metrics.file.max_rolling_size";
public static final String METRICS_FILE_COUNT = "servicecomb.metrics.file.max_rolling_count";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

public void updateImpl(List<Metric> metrics) {
Preconditions.checkNotNull(metrics, "metrics");
//这些参数是一次一起计算的,所以不需要将它们转化为独立的Metric,直接取值输出
Map<String, String> queueMetrics = metricsRegistry.calculateQueueMetrics();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single Responsibility!!! Do not get the metrics here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add MetricsContentConvertor interface to convert metrics and add MetricsContentFormatter interface to format output style

private final MetricsServoRegistry metricsRegistry;
private final MetricsFileOutput metricsOutput;

public SeparatedMetricObserver(String observerName, MetricsFileOutput metricsOutput,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of Separated?

InetAddress localHost = InetAddress.getLocalHost();
hostName = localHost.getHostName();
} catch (UnknownHostException e) {
e.printStackTrace();
Copy link
Member

@WillemJiang WillemJiang Nov 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the logger to log the exception. The UnknownHost is not a good solution here, we can still use IP address as the HostName.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NetUtils already have this information?

Microservice microservice = RegistryUtils.getMicroservice();
applicationName = String.join(".", microservice.getAppId(), microservice.getServiceName());
} else {
applicationName = String.join(".", hostName, "test");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the mean of test, if you just want to make the UT passed, it's not an acceptable reason.

fileAppender.setLogPermission("rw-------");
fileAppender.setFile(finalPath);
fileAppender.setLayout(new PatternLayout("%m%n"));
fileAppender.setThreshold(Priority.FATAL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you chose the FATAL?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

try {
SeparatedOutputData outputData = new SeparatedOutputData(this.applicationName, hostName, metricName,
metrics.get(metricName));
event = new LoggingEvent(fileName, Category.getInstance(fileName), Priority.FATAL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use the deprecated method here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

event = new LoggingEvent(fileName, Category.getInstance(fileName), Priority.FATAL,
mapper.writeValueAsString(outputData), null);
} catch (JsonProcessingException e) {
logger.error("parse metric data error");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not eating the exception!!!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

class SeparatedOutputData {
private String plugin_id = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the camel case for none constant variable.


class SeparatedOutputData {
private String plugin_id = null;
private Map<String, Object> metric = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This metric filed is useless, please remove it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's used for json serialize

configuration.setProperty(MetricsFileOutput.METRICS_POLL_TIME, 1);
configuration.setProperty(MetricsFileOutput.METRICS_FILE_ENABLED, true);

// configuration.setProperty(MetricsFileOutput.METRICS_FILE_PATH, "D:/Temp");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the commented code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


DynamicPropertyFactory.initWithConfigurationSource(configuration);
MetricsServoRegistry.metricsList.clear();
MetricsServoRegistry.LOCAL_METRICS_MAP = new ThreadLocal<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this static variable.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 86.899% when pulling 866a35c on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

Microservice microservice = RegistryUtils.getMicroservice();
fileNameHeader = String.join(".", microservice.getAppId(), microservice.getServiceName());
} else {
fileNameHeader = String.join(".", "local", "test");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw the exception here, as we cannot find the microservice information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

private final ObjectMapper mapper = new ObjectMapper();

@Override
public Map<String, String> convert(List<Metric> metrics) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convert logic is too complex, we need to find a way simplify it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes because current metrics such as QueueMetrics and TPS etc is information metrics type , will improve later

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i hate current mechanism
everything is string.
i think our metrics result should be a model......

maybe we need to refactor metrics after this PR at once.

return formattedMetrics;
}

class SeparatedOutputData {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json data object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@WillemJiang WillemJiang requested a review from wujimin November 25, 2017 08:08
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 86.94% when pulling 73038df on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 86.914% when pulling 85dc549 on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 86.927% when pulling 5639977 on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

super.subAppend(event);
}

public void setMaxBackupIndex(int maxBackups) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need to add this code?
base class already public it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed,removed

<scope>test</scope>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java-chassis-core already depend on swagger-invocation-core

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed,removed

public static final String METRICS_POLL_TIME = "servicecomb.metrics.polltime";
public static final String METRICS_FILE_ENABLED = "servicecomb.metrics.file.enabled";

private final int metricPoll;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not format code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatted , but I only change one setting "blank lines around fields" to 0,not 1,I think is ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fiexed,use current format style (set "blank lines around fields" to 1)


//manage and init ServoObservers
@Component
public class MetricsServoObserverManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not see what's the purpose of the manager.
it seems special for file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It use for init Servo PollScheduler,PollRunner and Observers

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the class name to MetricsObserverInitializer and move it into io.servicecomb.foundation.metrics.output.servo package


tpsAndLatencyMap.put("TPS Instance_Level", String.valueOf(insTotalTps));
tpsAndLatencyMap.put("Latency Instance_Level", String.valueOf(instanceLatency));
tpsAndLatencyMap.put("tps", String.valueOf(insTotalTps));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tps is a double?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course,transaction per seconds

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed , request may very low , current use double is better

tpsAndLatencyMap.put("TPS Instance_Level", String.valueOf(insTotalTps));
tpsAndLatencyMap.put("Latency Instance_Level", String.valueOf(instanceLatency));
tpsAndLatencyMap.put("tps", String.valueOf(insTotalTps));
tpsAndLatencyMap.put("latency", String.valueOf(instanceLatency));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the length of latency string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry what's means

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "servicecomb.metrics.round_places“ setting set round places ,default is 1


public Microservice load() {
try {
//TODO: has any better way get appId and microserviceName ? new MicroserviceDefinition may heavy cost
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appId and microserviceName support placeholder
but this code can not support it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry placeholder is what ? i don't see other process in RegistryUtils...


private static final Logger logger = LoggerFactory.getLogger(SimpleMetricsContentFormatter.class);
private final String applicationName;
private final ObjectMapper mapper = new ObjectMapper();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonUtils

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@wujimin
Copy link
Contributor

wujimin commented Nov 25, 2017

i don't think it's OK
but if we need the metrics output emergency, then merge it. and need to refactor at once.

@wujimin
Copy link
Contributor

wujimin commented Nov 25, 2017

foundation <- common <- service-registry <- core <-(provider/handler/transport)
this is our dependency order

but now, foundation depend on core......

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 86.902% when pulling 2549eef on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 86.932% when pulling 25a8421 on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

@WillemJiang
Copy link
Member

For the dependency issue, foundation <- common <- service-registry <- core <-(provider/handler/transport)
Maybe we introduce an API module to hold the management API that metrics need to use ( I think there could introduce lots of work) , otherwise we just put metrics to the (provider/handler/transport) layer which can have
the dependency of core.

@zhengyangyong
Copy link
Author

resolved dependency problem of foundation-metrics , current is


io.servicecomb
foundation-common


com.netflix.servo
servo-core


com.netflix.hystrix
hystrix-core


com.netflix.archaius
archaius-core


org.slf4j
slf4j-log4j12
test

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 86.892% when pulling 41d7591 on zhengyangyong:JAV-526 into 8eee2a2 on ServiceComb:master.

zhengyangyong added 12 commits November 27, 2017 15:39
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
…put only write file

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
…tion test (pojo)

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
…serviceName join string (metrics file name)

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
…n-metrics not dependency any other modules

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
@zhengyangyong
Copy link
Author

pull latest master from servicecomb and rebase on it

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 86.873% when pulling 230bea7 on zhengyangyong:JAV-526 into f9bcb13 on ServiceComb:master.

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 86.968% when pulling d769522 on zhengyangyong:JAV-526 into f9bcb13 on ServiceComb:master.

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 87.05% when pulling 512aab5 on zhengyangyong:JAV-526 into f9bcb13 on ServiceComb:master.

@WillemJiang
Copy link
Member

Please remember to update the document of how to use it?

@WillemJiang WillemJiang merged commit b9d2bcd into apache:master Nov 29, 2017
@zhengyangyong zhengyangyong deleted the JAV-526 branch March 27, 2018 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants