Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
czd890 opened this issue Jan 24, 2024 · 4 comments
Closed

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

czd890 opened this issue Jan 24, 2024 · 4 comments
Labels

Comments

@czd890
Copy link
Contributor

czd890 commented Jan 24, 2024

  • 在主版本中是否可以格式检查, 不通过不让点击保存
    1706083358802

  • 在灰度中类似k-v的类型检查(比如说当前namespace是json的, 修改灰度配置项这里的类型可以是固定死的json)
    1706083056816

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

Copy link

dosubot bot commented Jan 24, 2024

🤖

你好,@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
Copy link
Member

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

Copy link

stale bot commented Feb 24, 2024

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 stale bot added the stale label Feb 24, 2024
Copy link

stale bot commented Mar 3, 2024

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.

@stale stale bot closed this as completed Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants