Skip to content

Commit 5f9c4fb

Browse files
authored
Feature/list inactive topics (#15)
* added list empty topics to lister interface and test lister users * upgraded sarama version to 1.27.2 and updated corresponding dependencies * added implementation to fetch empty Topics and relevant tests * add vs code confs to gitignore reformat list topic and mockclusteradmin.go * changes to use time pacakge instead of dealing with int64 * refactored tests and sarama client to have simpler interfaces Moved size filtering logic to topic.go * pipelined and added context to coordinate quiting of go routines * bug fix on race condition in topic selection * added goroutine leak check * elaborated size flag documentation * update circleci image to go1.13 * fixed goroutine leak by adding select case on channel enqueing reduced cyclometric complexity by extracting out helper functions * remove working directory for circleci build * added github actions config, deleted circle ci conf * fixed arbitarily failing test for listconsumer Co-authored-by: punit-kulal <[email protected]>
1 parent 719698d commit 5f9c4fb

22 files changed

+740
-184
lines changed

.circleci/config.yml

Lines changed: 0 additions & 104 deletions
This file was deleted.

.github/workflows/pull-request.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: pull-request
2+
on:
3+
pull_request:
4+
jobs:
5+
build:
6+
name: build
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: setup-go
11+
uses: actions/setup-go@v2
12+
with:
13+
go-version: '^1.13.1'
14+
- name: setup-project
15+
run: make setup
16+
- name: build
17+
run: |
18+
env GO111MODULE=on go mod verify
19+
env GO111MODULE=on make clean build
20+
test:
21+
name: test
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: setup-go
26+
uses: actions/setup-go@v2
27+
with:
28+
go-version: '^1.13.1'
29+
- name: setup-project
30+
run: make setup
31+
- name: test
32+
run: make test
33+
golangci:
34+
name: golangci
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v2
38+
- name: setup-go
39+
uses: actions/setup-go@v2
40+
with:
41+
go-version: '^1.13.1'
42+
- name: setup-project
43+
run: make setup
44+
- name: lint
45+
run: make golangci

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ vendor/
44
*.swp
55
out/
66
coverage*
7+
.vscode/
8+
bin/

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ run:
7676
skip-dirs:
7777
- test/testdata_etc
7878
- pkg/golinters/goanalysis/(checker|passes)
79+
- pkg/io #inbuilt package throws permission error, hence excluded
7980
tests: false
8081

8182
issues:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ vet:
4444
go vet ./...
4545

4646
golangci:
47-
GO111MODULE=off go get -v github.com/golangci/golangci-lint/cmd/golangci-lint
48-
golangci-lint run -v --deadline 5m0s
47+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b bin/ v1.30.0
48+
bin/golangci-lint run -v --deadline 5m0s
4949

5050
test-coverage:
5151
mkdir -p ./out

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ kat topic list --broker-list <"broker1:9092,broker2:9092"> --replication-factor
5555
kat topic list --broker-list <"broker1:9092,broker2:9092"> --last-write=<epoch time> --data-dir=<kafka logs directory>
5656
```
5757

58+
* List topic with size less than or equal to given size
59+
```
60+
kat topic list --broker-list <"broker1:9092,broker2:9092"> --size=<size in bytes>
61+
```
62+
5863
Topic throughput metrics or last modified time is not available in topic metadata response from kafka. Hence, this tool has a custom implementation of ssh'ing into all the brokers and filtering through the kafka logs directory to find the topics that were not written after the given time.
5964

6065
### Describe Topics

cmd/list/listconsumergroup_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ func TestListGroupsReturnsSuccess(t *testing.T) {
2828

2929
consumerGroupsMap := map[string]string{"consumer1": "", "consumer2": ""}
3030
mockConsumer.On("ListConsumerGroups").Return(consumerGroupsMap, nil)
31-
32-
mockConsumer.On("GetConsumerGroupsForTopic", []string{"consumer1", "consumer2"}, "").Return(mockChannel, nil)
31+
validateParams := func(token []string) bool {
32+
return (token[0] == "consumer1" && token[1] == "consumer2") || (token[0] == "consumer2" && token[1] == "consumer1")
33+
}
34+
mockConsumer.On("GetConsumerGroupsForTopic", mock.MatchedBy(validateParams), "").Return(mockChannel, nil)
3335

3436
err := admin.ListGroups("")
3537

0 commit comments

Comments
 (0)