Skip to content

Commit bc8eab2

Browse files
committed
[feat][metrics] Add option to remove all custom metric labels for topics
1 parent d235271 commit bc8eab2

File tree

1 file changed

+15
-5
lines changed
  • pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli

1 file changed

+15
-5
lines changed

pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,14 +3095,16 @@ private class SetCustomMetricLabels extends CliCommand {
30953095
@Parameters(description = "persistent://tenant/namespace/topic", arity = "1")
30963096
private String topicName;
30973097

3098-
@Option(names = {"--labels", "-l"}, description = "Custom metric labels (key=value pairs, comma separated, e.g. sla_tier=gold,app_owner=team-a)", required = true)
3098+
@Option(names = {"--labels",
3099+
"-l"}, description = "Custom metric labels (key=value pairs, comma separated, e.g. sla_tier=gold,"
3100+
+ "app_owner=team-a)", required = true)
30993101
private String labelsStr;
31003102

31013103
@Override
31023104
void run() throws PulsarAdminException {
31033105
String topic = validateTopicName(topicName);
31043106
Map<String, String> labels = new HashMap<>();
3105-
3107+
31063108
if (labelsStr != null && !labelsStr.trim().isEmpty()) {
31073109
String[] pairs = labelsStr.split(",");
31083110
for (String pair : pairs) {
@@ -3123,16 +3125,24 @@ private class RemoveCustomMetricLabels extends CliCommand {
31233125
@Parameters(description = "persistent://tenant/namespace/topic", arity = "1")
31243126
private String topicName;
31253127

3126-
@Option(names = {"--keys", "-k"}, description = "Label keys to remove (comma separated, e.g. sla_tier,app_owner). If not specified, all labels will be removed.", required = false)
3128+
@Option(names = {"--keys", "-k"}, description = "Label keys to remove"
3129+
+ " (comma separated, e.g. sla_tier,app_owner). If not specified, "
3130+
+ "all labels will be removed.", required = false)
31273131
private String keysStr;
31283132

3133+
@Option(names = {"--all", "-a"}, description = "Remove all labels", required = false)
3134+
private boolean removeAll;
3135+
31293136
@Override
31303137
void run() throws PulsarAdminException {
31313138
String topic = validateTopicName(topicName);
3132-
3133-
if (keysStr != null && !keysStr.trim().isEmpty()) {
3139+
3140+
if (!removeAll) {
31343141
List<String> keys = Arrays.asList(keysStr.split(","));
31353142
keys = keys.stream().map(String::trim).collect(Collectors.toList());
3143+
if (keys.isEmpty()) {
3144+
throw new ParameterException("No label keys specified for removal.");
3145+
}
31363146
getAdmin().topicPolicies().removeCustomMetricLabels(topic, false, keys);
31373147
} else {
31383148
// Remove all labels

0 commit comments

Comments
 (0)