forked from apache/incubator-seata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor metrics let it initialize by configuration (apache#1245)
Signed-off-by: zhengyangyong <[email protected]>
- Loading branch information
1 parent
735f409
commit 55adfef
Showing
31 changed files
with
387 additions
and
104 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
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
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
56 changes: 56 additions & 0 deletions
56
metrics/seata-metrics-core/src/main/java/io/seata/metrics/exporter/ExporterFactory.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,56 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed 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 io.seata.metrics.exporter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import io.seata.common.loader.EnhancedServiceLoader; | ||
import io.seata.common.util.StringUtils; | ||
import io.seata.config.ConfigurationFactory; | ||
import io.seata.metrics.constants.ConfigurationKeys; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Exporter Factory for load all configured exporters | ||
* | ||
* @author zhengyangyong | ||
*/ | ||
public class ExporterFactory { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ExporterFactory.class); | ||
|
||
public static List<Exporter> getInstanceList() { | ||
List<Exporter> exporters = new ArrayList<>(); | ||
String exporterTypeNameList = ConfigurationFactory.getInstance().getConfig( | ||
ConfigurationKeys.METRICS_PREFIX + ConfigurationKeys.METRICS_EXPORTER_LIST, null); | ||
if (!StringUtils.isNullOrEmpty(exporterTypeNameList)) { | ||
String[] exporterTypeNames = exporterTypeNameList.split(","); | ||
for (String exporterTypeName : exporterTypeNames) { | ||
ExporterType exporterType; | ||
try { | ||
exporterType = ExporterType.getType(exporterTypeName); | ||
exporters.add( | ||
EnhancedServiceLoader.load(Exporter.class, Objects.requireNonNull(exporterType).name())); | ||
} catch (Exception exx) { | ||
LOGGER.error("not support metrics exporter type: " + exporterTypeName, exx); | ||
} | ||
} | ||
} | ||
return exporters; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
metrics/seata-metrics-core/src/main/java/io/seata/metrics/exporter/ExporterType.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,38 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed 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 io.seata.metrics.exporter; | ||
|
||
import io.seata.common.exception.NotSupportYetException; | ||
|
||
/** | ||
* Supported metrics exporter type | ||
* | ||
* @author zhengyangyong | ||
*/ | ||
public enum ExporterType { | ||
/** | ||
* Export metrics data to Prometheus | ||
*/ | ||
Prometheus; | ||
|
||
public static ExporterType getType(String name) { | ||
if (Prometheus.name().equalsIgnoreCase(name)) { | ||
return Prometheus; | ||
} else { | ||
throw new NotSupportYetException("unsupported type:" + name); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
metrics/seata-metrics-core/src/main/java/io/seata/metrics/registry/RegistryFactory.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,46 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed 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 io.seata.metrics.registry; | ||
|
||
import java.util.Objects; | ||
|
||
import io.seata.common.exception.NotSupportYetException; | ||
import io.seata.common.loader.EnhancedServiceLoader; | ||
import io.seata.common.util.StringUtils; | ||
import io.seata.config.ConfigurationFactory; | ||
import io.seata.metrics.constants.ConfigurationKeys; | ||
|
||
/** | ||
* Registry Factory for load configured metrics registry | ||
* | ||
* @author zhengyangyong | ||
*/ | ||
public class RegistryFactory { | ||
public static Registry getInstance() { | ||
RegistryType registryType; | ||
String registryTypeName = ConfigurationFactory.getInstance().getConfig( | ||
ConfigurationKeys.METRICS_PREFIX + ConfigurationKeys.METRICS_REGISTRY_TYPE, null); | ||
if (!StringUtils.isNullOrEmpty(registryTypeName)) { | ||
try { | ||
registryType = RegistryType.getType(registryTypeName); | ||
} catch (Exception exx) { | ||
throw new NotSupportYetException("not support metrics registry type: " + registryTypeName); | ||
} | ||
return EnhancedServiceLoader.load(Registry.class, Objects.requireNonNull(registryType).name()); | ||
} | ||
return null; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
metrics/seata-metrics-core/src/main/java/io/seata/metrics/registry/RegistryType.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,38 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed 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 io.seata.metrics.registry; | ||
|
||
import io.seata.common.exception.NotSupportYetException; | ||
|
||
/** | ||
* Supported metrics registry type | ||
* | ||
* @author zhengyangyong | ||
*/ | ||
public enum RegistryType { | ||
/** | ||
* Built-in compact metrics registry | ||
*/ | ||
Compact; | ||
|
||
public static RegistryType getType(String name) { | ||
if (Compact.name().equalsIgnoreCase(name)) { | ||
return Compact; | ||
} else { | ||
throw new NotSupportYetException("unsupported type:" + name); | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
metrics/seata-metrics-core/src/main/resources/META-INF/services/io.seata.metrics.Registry
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.