-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add metrics support of error code * Add metrics support of error code * Add metrics support of error code * add license * remove hashcode override * Update DefaultSubDispatcher.java * Update ErrorCodeSampleTest.java * Update DefaultMetricsCollector.java --------- Co-authored-by: songxiaosheng <[email protected]>
- Loading branch information
1 parent
04f3fe7
commit 5ae875d
Showing
17 changed files
with
455 additions
and
48 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
32 changes: 32 additions & 0 deletions
32
dubbo-common/src/main/java/org/apache/dubbo/common/logger/ListenableLogger.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,32 @@ | ||
/* | ||
* 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.dubbo.common.logger; | ||
|
||
/** | ||
* Loggers that can register to listen to log messages. | ||
*/ | ||
public interface ListenableLogger extends ErrorTypeAwareLogger{ | ||
|
||
/** | ||
* Register a listener to this logger,and get notified when a log happens. | ||
* | ||
* @param listener log listener | ||
*/ | ||
void registerListen(LogListener listener); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
dubbo-common/src/main/java/org/apache/dubbo/common/logger/LogListener.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,27 @@ | ||
/* | ||
* 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.dubbo.common.logger; | ||
|
||
/** | ||
* Log Listener, can registered to an {@link ListenableLogger}. | ||
*/ | ||
public interface LogListener { | ||
|
||
void onMessage(String code, String msg); | ||
|
||
} |
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
51 changes: 51 additions & 0 deletions
51
...trics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/ErrorCodeMetric.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,51 @@ | ||
/* | ||
* 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.dubbo.metrics.model; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.apache.dubbo.common.constants.MetricsConstants.TAG_APPLICATION_NAME; | ||
import static org.apache.dubbo.common.constants.MetricsConstants.TAG_ERROR_CODE; | ||
|
||
/** | ||
* ErrorCodeMetric. Provide tags for error code metrics. | ||
*/ | ||
public class ErrorCodeMetric implements Metric { | ||
|
||
private final String errorCode; | ||
|
||
private final String applicationName; | ||
|
||
public ErrorCodeMetric(String applicationName, String errorCode) { | ||
this.errorCode = errorCode; | ||
this.applicationName = applicationName; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getTags() { | ||
Map<String, String> tags = new HashMap<>(); | ||
tags.put(TAG_ERROR_CODE, errorCode); | ||
tags.put(TAG_APPLICATION_NAME, applicationName); | ||
return tags; | ||
} | ||
|
||
public String getErrorCode() { | ||
return errorCode; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -29,5 +29,6 @@ public enum MetricsCategory { | |
REGISTRY, | ||
METADATA, | ||
THREAD_POOL, | ||
ERROR_CODE, | ||
NETTY, | ||
} |
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
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
41 changes: 41 additions & 0 deletions
41
...c/main/java/org/apache/dubbo/metrics/collector/sample/ErrorCodeMetricsListenRegister.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,41 @@ | ||
/* | ||
* 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.dubbo.metrics.collector.sample; | ||
|
||
import org.apache.dubbo.common.logger.LogListener; | ||
import org.apache.dubbo.common.logger.support.FailsafeErrorTypeAwareLogger; | ||
import org.apache.dubbo.metrics.model.key.MetricsKey; | ||
|
||
/** | ||
* Listen the log of all {@link FailsafeErrorTypeAwareLogger} instances, and add error code count to {@link ErrorCodeSampler}. | ||
*/ | ||
public class ErrorCodeMetricsListenRegister implements LogListener { | ||
|
||
private final ErrorCodeSampler errorCodeSampler; | ||
|
||
public ErrorCodeMetricsListenRegister(ErrorCodeSampler errorCodeSampler){ | ||
FailsafeErrorTypeAwareLogger.registerGlobalListen(this); | ||
this.errorCodeSampler = errorCodeSampler; | ||
this.errorCodeSampler.addMetricName(MetricsKey.ERROR_CODE_COUNT.getName()); | ||
} | ||
|
||
@Override | ||
public void onMessage(String code, String msg) { | ||
errorCodeSampler.inc(code, MetricsKey.ERROR_CODE_COUNT.getName()); | ||
} | ||
} |
Oops, something went wrong.