Skip to content

Conversation

@garyparrot
Copy link
Collaborator

@garyparrot garyparrot commented Nov 23, 2021

resolve #89

This PR implements a tool to monitor replica syncing progress, it can be used to monitor replica migration progress.

Flags

Usage: <main class> [options]
  Options:
  * --bootstrap.servers String: server to connect to
    --interval          Time: the time interval between replica state check, 
                        support multiple time unit like 10s, 500ms and 100us. 
                        If no time unit specified, second unit will be used. 
                        (default: PT1S)
    --prop.file         the file path containing the properties to be passed 
                        to kafka admin
    --topics            String: topics to track, use all non-synced topics by 
                        default (default: [])
    --track             Boolean: keep track even if all the replicas are 
                        synced, also attempts to discover any non-synced 
                        replicas (default: false)

Example Code

package org.astraea;

import java.net.MalformedURLException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import org.astraea.topic.ReplicaSyncingMonitor;
import org.astraea.topic.TopicAdmin;

public class Ignore {

  public static void main(String[] args) throws MalformedURLException, InterruptedException {
    final String topicName = "sad-af";
    try (TopicAdmin admin = TopicAdmin.builder().brokers("localhost:9092").build()) {
      // admin.creator()
      //         .topic(topicName)
      //         .numberOfPartitions(2)
      //         .numberOfReplicas((short)1)
      //         .create();

      // dump data
      // Sender<byte[], byte[]> sadsadsad = Producer.of("localhost:9092")
      //         .sender()
      //         .topic(topicName)
      //         .partition(0)
      //         .value(new byte[1024]);
      // IntStream.range(0, 1024 * 32)
      //         .mapToObj(i -> sadsadsad.run().toCompletableFuture())
      //         .forEach(CompletableFuture::join);

      // move replicas
      admin.migrator().partition(topicName, 0).partition(topicName, 1).moveTo(Set.of(0));
      TimeUnit.SECONDS.sleep(2);
      admin.migrator().partition(topicName, 0).partition(topicName, 1).moveTo(Set.of(0, 2));

      // run syncing monitor
      ReplicaSyncingMonitor.main(
          new String[] {
            "--bootstrap.servers", "localhost:9092", "--track", "--interval", "500ms"
          });

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Demo

[2021-11-23T16:00:26.282676667]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [                    ]   1.37% 0.00 B/s (unknown) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [                    ]   1.35% 0.00 B/s (unknown) []

[2021-11-23T16:00:26.862637796]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#                   ]   5.62% 240.54 MB/s (11s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#                   ]   5.25% 242.53 MB/s (12s estimated) []

[2021-11-23T16:00:27.400814839]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##                  ]   9.90% 242.53 MB/s (10s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##                  ]   9.13% 240.54 MB/s (11s estimated) []

[2021-11-23T16:00:27.927354298]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##                  ]  13.86% 224.62 MB/s (10s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##                  ]  12.78% 226.62 MB/s (11s estimated) []

[2021-11-23T16:00:28.455388779]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [###                 ]  17.90% 228.61 MB/s (10s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [###                 ]  16.43% 226.62 MB/s (11s estimated) []

[2021-11-23T16:00:28.980529178]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [####                ]  22.29% 248.49 MB/s (8s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [####                ]  20.43% 248.49 MB/s (9s estimated) []

[2021-11-23T16:00:29.507726612]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#####               ]  26.25% 224.64 MB/s (9s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#####               ]  24.05% 224.64 MB/s (10s estimated) []

[2021-11-23T16:00:30.032282648]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [######              ]  29.76% 198.79 MB/s (10s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#####               ]  27.25% 198.79 MB/s (11s estimated) []

[2021-11-23T16:00:30.558955923]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [######              ]  33.06% 186.87 MB/s (10s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [######              ]  30.26% 186.90 MB/s (11s estimated) []

[2021-11-23T16:00:31.086946056]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#######             ]  36.20% 177.37 MB/s (10s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [######              ]  33.12% 177.31 MB/s (11s estimated) []

[2021-11-23T16:00:31.621153809]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#######             ]  38.16% 111.32 MB/s (15s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#######             ]  34.91% 111.32 MB/s (18s estimated) []

[2021-11-23T16:00:32.155653568]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [########            ]  40.69% 143.13 MB/s (11s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#######             ]  37.22% 143.13 MB/s (13s estimated) []

[2021-11-23T16:00:32.676049858]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#########           ]  44.48% 214.70 MB/s (7s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [########            ]  40.68% 214.72 MB/s (8s estimated) []

[2021-11-23T16:00:33.204855108]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#########           ]  48.59% 232.59 MB/s (6s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#########           ]  44.43% 232.59 MB/s (7s estimated) []

[2021-11-23T16:00:33.726890852]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##########          ]  52.66% 230.60 MB/s (5s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#########           ]  48.14% 230.60 MB/s (6s estimated) []

[2021-11-23T16:00:34.25271772]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [###########         ]  56.69% 228.60 MB/s (5s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##########          ]  51.86% 230.60 MB/s (6s estimated) []

[2021-11-23T16:00:34.770989298]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [############        ]  60.76% 230.60 MB/s (4s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [###########         ]  55.57% 230.60 MB/s (5s estimated) []

[2021-11-23T16:00:35.295123144]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#############       ]  64.70% 222.65 MB/s (4s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [############        ]  59.13% 220.66 MB/s (5s estimated) []

[2021-11-23T16:00:35.821856063]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#############       ]  68.56% 218.67 MB/s (4s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [############        ]  62.65% 218.67 MB/s (5s estimated) []

[2021-11-23T16:00:36.34655702]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##############      ]  72.24% 208.73 MB/s (3s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#############       ]  65.99% 207.13 MB/s (5s estimated) []

[2021-11-23T16:00:36.870404587]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##############      ]  73.13% 50.11 MB/s (15s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#############       ]  66.82% 51.69 MB/s (19s estimated) []

[2021-11-23T16:00:37.39039014]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##############      ]  73.48% 19.88 MB/s (37s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#############       ]  67.14% 19.88 MB/s (51s estimated) []

[2021-11-23T16:00:37.911614747]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [###############     ]  74.81% 75.54 MB/s (9s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#############       ]  68.39% 77.53 MB/s (12s estimated) []

[2021-11-23T16:00:38.434778218]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [###############     ]  78.88% 230.59 MB/s (2s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##############      ]  72.10% 230.60 MB/s (3s estimated) []

[2021-11-23T16:00:38.959356813]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [################    ]  82.78% 220.67 MB/s (2s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [###############     ]  75.62% 218.67 MB/s (3s estimated) []

[2021-11-23T16:00:39.484573199]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#################   ]  86.99% 238.54 MB/s (1s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [################    ]  79.47% 238.55 MB/s (2s estimated) []

[2021-11-23T16:00:40.006485324]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##################  ]  90.92% 222.52 MB/s (1s estimated) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [################    ]  83.05% 222.65 MB/s (2s estimated) []

[2021-11-23T16:00:40.522097276]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [################### ]  94.61% 208.80 MB/s (about now) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [#################   ]  86.42% 208.73 MB/s (2s estimated) []

[2021-11-23T16:00:41.038080015]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [################### ]  97.80% 180.89 MB/s (about now) []
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##################  ]  89.33% 180.90 MB/s (1s estimated) []

[2021-11-23T16:00:41.56029113]
  Topic "sadsadsad":
  │ Partition 0:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [####################] 100.00% 124.54 MB/s (about now) [synced]
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [##################  ]  91.45% 131.20 MB/s (2s estimated) []

[2021-11-23T16:00:42.078556842]
  Topic "sadsadsad":
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [################### ]  95.67% 262.41 MB/s (about now) []

[2021-11-23T16:00:42.596646832]
  Topic "sadsadsad":
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [####################]  99.46% 234.99 MB/s (about now) []

[2021-11-23T16:00:43.118400487]
  Topic "sadsadsad":
  │ Partition 1:
  │ │ replica on broker   0 => [####################] 100.00% [leader, synced]
  │ │ replica on broker   2 => [####################] 100.00% 33.62 MB/s (about now) [synced]
  Every replica is synced.

[2021-11-23T16:00:43.63729037]
  Every replica is synced.

[2021-11-23T16:00:44.15813951]
  Every replica is synced.

[2021-11-23T16:00:44.67613745]
  Every replica is synced.

[2021-11-23T16:00:45.193653415]
  Every replica is synced.

....

TODO

  • update README.md

ReplicaSyncingMonitor#dateRate shouldn't be a implementation detail
Use --interval to specify the frequency of replics progress check.

This is a useful flag for user who want faster feedback, also the
existence of this flag enable us to have the tests run quicker.
@garyparrot garyparrot self-assigned this Nov 23, 2021
@garyparrot garyparrot requested a review from chia7712 November 23, 2021 08:08
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garyparrot 能否麻煩更新readme?

@CsvSource(
delimiterString = ",",
value = {
// leaderSize, previousSize, currentSize, interval, dataRatePerSec, Progress, Remaining, ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

為何最後有一個?

Copy link
Collaborator Author

@garyparrot garyparrot Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最後那個多餘的欄位是在描述這筆測試輸入的意義,當初好像因為寫太長會讓 spotless 嘗試將 comment 分到下一行,所以沒辦法取一些比較有意義的名稱(比如 test-purpose)

我可以試著把他弄得比較正常一些

.collect(Collectors.joining(" ", "", " estimated"));
}

public String dataRateString() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這個動作在其他工具應該也會用到,看看能否寫成一個公用的class讓大家可以輕鬆將數字在不同單位轉換

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果你同意我上述的意見的話,麻煩先開一個議題,然後將議題編號回覆到此討論串

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我開在 #121 了,謝謝

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712 我應該在這個 PR 內處理#121議題嗎,或是之後再開一個獨立的 PR 處理

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外開PR處理,這裡可以保持原樣

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garyparrot 感謝回覆,還有一些意見請看一下


static void execute(final TopicAdmin topicAdmin, final Argument argument) {

// this supplier will gives you all the topic name that the client interest in.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gives -> give

converter = MillisecondConverter.class)
public int interval = 1000;

public static class MillisecondConverter implements IStringConverter<Integer> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

喔 我本來的意思是說 可以的話盡量共用時間的轉換 (see ArgumentUtil#DurationConverter)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我剛剛看了一下 ArgumentUtil#DurationConverter 似乎只能做到 Second 單位的讀取,可能不適合這種可以接受 millisecond 的。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

說到毫秒 這個例子需要毫秒嗎?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只能用到秒單位對某些人來說可能有點慢,可能有人想 0.5 秒(500ms)看一次進度。

https://github.com/skiptests/astraea/pull/119/files#diff-5207e4edbe5dc490ae59e46c341451f51ebecb8829f9bd4cdca14c1b82858367R59
然後測試裡面有一些情境需要從 main 執行來測試工具有沒有滿足某些業務需求。如果裡面一秒跑一輪的話可能整個測試會跑很久,像是上面那個連接就使用 10ms 來加快這個測試的速度

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另一個角度是說我們應該要支持“有單位“這件事情,例如可以輸入 10s or 10ms 這類的數字來作為“時間區段"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那我再把它修改成能夠支援數字和時間單位的形式,可能寫一個專門給時間的 Converter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這可能要在這隻PR完成比較好 這樣可以減少參數改動的次數

public Set<String> topics = Set.of(EVERY_TOPIC);

@Parameter(
names = {"--keep-track"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因為已經有doc了,看能否用track就好

static void execute(final TopicAdmin topicAdmin, final Argument argument) {

// this supplier will gives you all the topic name that the client interest in.
Supplier<Set<String>> topicToTrack =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同樣,請盡量用var

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊好像沒辦法 var, 編譯器沒辦法 infer 他的 type

/home/garyparrot/Programming/astraea/app/src/main/java/org/astraea/topic/ReplicaSyncingMonitor.java:33: error: cannot infer type for local variable topicToTrack
    var topicToTrack =
        ^
  (lambda expression needs an explicit target-type)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

等下,為何這邊要用Supplier? 此時此刻就先決定有哪些topics不行嗎?

Copy link
Collaborator Author

@garyparrot garyparrot Nov 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這和我當初定義的 --topic 的語義有關,--topic 留空時,會選擇叢集內的 non-synced replica 做監控

但是 --track flag 有一個需求是除了能持續執行,還要能挖掘其他新出現的 non-synced replica。在程式開始執行時就固定會違反 --track 的需求。

當初會弄成這樣是因為我覺得這個情境應該蠻常見的,可能某人想持續監控任何新的 non-synced replica, 而非要經常重跑程式刷新。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你講的很有道理,可否加上註解說明你的原因?

names = {"--topic"},
description = "String: topics to track",
validateWith = ArgumentUtil.NotEmptyString.class)
public Set<String> topics = Set.of(EVERY_TOPIC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要否直接用empty set來代表所有topics?

.collect(Collectors.joining(" ", "", " estimated"));
}

public String dataRateString() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果你同意我上述的意見的話,麻煩先開一個議題,然後將議題編號回覆到此討論串

Due to some complicate issue the default value of --interval looks
like 1000 in help message even if it means 1 second instead of 1000
seconds.

This commit fixes this by changing the type of --interval argument to
double.

This commit also enhances the test by covering the illegal interval
value.
This reverts commit f6c06f7.

Instead of deciding which time unit for --interval flag to use. We can
just let users make this decision.

In the next commit, I will implement a converter that lets users specify
their time unit.
Now flag --interval support time unit with the help of TimeConverter,
following string are valid argument for --interval.

* 30days
* 30day
* 24h
* 12m
* 50s
* 20
* 500ms
* 500us
* 500ns
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garyparrot 感謝如此棒的patch,剩一些小建議,請看一下,然後就來合併!

README.md Outdated
5. [Kafka metric client](#kafka-metric-client): utility for accessing kafka Mbean metrics via JMX.
6. [Replica Collie](#replica-collie): move replicas from brokers to others. You can use this tool to obstruct specific brokers from hosting specific topics.
7. [Kafka partition score](#Kafka-partition-score): score all broker's partitions.
8. [Kafka relica syncing monitor](#Kafka-replica-syncing-monitor): Tracking replica syncing progress.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relica -> replica

* <li><b>(doesn't work)</b> {@code "0.5" to {@code Duration.ofMillis(500)}}
* </ul>
*/
public static class TimeConverter implements IStringConverter<Duration>, IParameterValidator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可否改名為DurationConverter,並且把舊版的刪掉?

static void execute(final TopicAdmin topicAdmin, final Argument argument) {

// this supplier will gives you all the topic name that the client interest in.
Supplier<Set<String>> topicToTrack =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

等下,為何這邊要用Supplier? 此時此刻就先決定有哪些topics不行嗎?

() -> argument.topics.isEmpty() ? topicAdmin.topicNames() : argument.topics;

// the non-synced topic-partition we want to monitor
Set<TopicPartition> topicPartitionToTrack =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var

findNonSyncedTopicPartition(topicAdmin, topicToTrack.get());

// keep tracking the previous replica size of a topic-partition-replica tuple
final Map<TopicPartitionReplica, Long> previousCheckedSize = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var

static class Argument extends BasicArgumentWithPropFile {

@Parameter(
names = {"--topic"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因為是複數,請用--topics

public void validate(String name, String value) throws ParameterException {
if (!timePattern.matcher(value).find())
throw new ParameterException(
"field \"" + name + "\"'s value \"" + value + "\" doesn't match time format");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊的錯誤訊息請至少包含一個例子

.collect(Collectors.toUnmodifiableList());

@Test
void execute() throws InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove InterruptedException


class ReplicaSyncingMonitorIntegrationTest extends RequireBrokerCluster {

private static final String topicName =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考量是global variable,請用大寫字母表示

" 60h, true , valid unit",
" 365day, true , valid unit",
" 365days, true , valid unit",
" 0010100days, true , valid unit",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我在思考 0 開頭的數字算不算合格的輸入,我個人覺得這個應該不能過

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果這不會把regex變得太複雜的話...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- Pattern.compile(          "^(?<value>[0-9]+)(?<unit>days|day|h|m|s|ms|us|ns|)$")
+ Pattern.compile("^(?!0[0-9])(?<value>[0-9]+)(?<unit>days|day|h|m|s|ms|us|ns|)$")

如果在前面套用上 negative lookahead 的話應該可行
不過我後來覺得算了,有 leading zero 的數字似乎要說他並非數字好像也不太對勁。

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garyparrot 這隻patch很棒!只剩一個小style麻煩改一下,謝謝

*/
public static class DurationConverter implements IStringConverter<Duration>, IParameterValidator {

static final Pattern timePattern =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static final Pattern TIME_PATTERN

@chia7712 chia7712 merged commit 6f8423e into opensource4you:main Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support to monitor migration progress

2 participants