apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
28.94k stars 10.19k forks source link

非kv格式的content也支持格式检查 #5080

Closed czd890 closed 4 months ago

czd890 commented 5 months ago

和k-v格式的namespace中的item差不多. 1706083276000

dosubot[bot] commented 5 months ago

🤖

你好,@czd890!很高兴再次看到你提出的问题。希望你一切都好!

是的,可以在Apollo的主版本中实现非KV内容的格式检查,以及在类似JSON的命名空间中实现灰度配置的类型检查,类似于KV格式命名空间中的项。

Apollo已经有一个用于验证集群和应用命名空间格式的机制。这是通过使用正则表达式(regex)和Java的Pattern类来完成的。

isValidClusterNamespaceisValidAppNamespace方法检查提供的命名空间名称是否与指定的regex模式匹配。如果匹配,方法返回true,表示命名空间名称有效。如果不匹配,方法返回false,表示命名空间名称无效。

要实现非KV内容的格式检查和灰度配置的类型检查,您需要定义适当的regex模式并创建类似的验证方法。regex模式需要设计为匹配您想要验证的格式和类型。

以下是一个简单的示例,说明如何实现验证JSON格式的方法:

private static final Pattern JSON_PATTERN = Pattern.compile("..."); // 将 ... 替换为适合 JSON 格式的正则表达式

public static boolean isValidJsonFormat(String content) {
  if (StringUtils.isEmpty(content)){
    return false;
  }
  return JSON_PATTERN.matcher(content).matches();
}

请在Pattern.compile方法中将...替换为适合JSON格式的正则表达式。

参考资料:

当前,Apollo中KV(键-值)内容的格式验证机制是通过Verifiable接口实现的。这个接口有一个isInvalid()方法,需要由需要验证其内容的类来实现。如果方法返回true,则表示内容无效;如果返回false,则内容有效。然而,具体的验证逻辑在给定的上下文中并未提供。

参考资料:

在Apollo中,灰度配置是通过GrayReleaseRuleDTO类处理的。这个类包含了定义灰度发布规则的几个属性,包括appIdclusterNamenamespaceNamebranchNameruleItemsreleaseId

参考资料:

Apollo中灰度配置的类型检查是通过GrayReleaseRulesHolder类实现的。这个类维护了两个缓存:grayReleaseRuleCachereversedGrayReleaseRuleCache

参考资料:

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

nobodyiam commented 5 months ago

可以作为一个配置项,有需要的用户可以开启

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 4 months ago

This issue has been automatically closed because it has not had activity in the last 7 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.