diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ee1e9..f4494b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,12 @@ All notable changes to Kafka extension will be documented in this file. ### Added - Newly created topic or cluster is automatically selected in the Kafka Explorer. See [#61](https://github.com/jlandersen/vscode-kafka/issues/61). - Click on empty Kafka explorer to add a new cluster. See [#76](https//github.com/jlandersen/vscode-kafka/pull/76). +- Added glob patterns to filter topics (`kafka.explorer.topics.filters`) and consumer groups (`kafka.explorer.consumers.filters`) out of the Kafka explorer. See [#74](https://github.com/jlandersen/vscode-kafka/pull/74). ### Changed - Improved the "New cluster" and "New topic" wizards: now include validation and a back button. See [#21](https://github.com/jlandersen/vscode-kafka/issues/21). - Newly created topic or cluster is automatically selected in the Kafka Explorer. See [#61](https://github.com/jlandersen/vscode-kafka/issues/61). +- Internal topics are now hidden by default. See [#29](https://github.com/jlandersen/vscode-kafka/issues/29) and [#74](https://github.com/jlandersen/vscode-kafka/pull/74). ## [0.10.0] - 2021-01-02 ### Added diff --git a/package.json b/package.json index 7282196..5797dc0 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,16 @@ "default": "name", "description": "Choose sorting for topics in explorer" }, + "kafka.explorer.topics.filter": { + "type": "array", + "default": ["__consumer_offsets", "__transaction_state", "_schemas"], + "markdownDescription": "Glob patterns filtering topics out of the Kafka explorer. `*` matches any string, `?` matches a single character." + }, + "kafka.explorer.consumers.filter": { + "type": "array", + "default": [], + "markdownDescription": "Glob patterns filtering consumer groups out of the Kafka explorer. `*` matches any string, `?` matches a single character." + }, "kafka.producers.fakerjs.enabled":{ "type": "boolean", "default":true, diff --git a/src/explorer/models/consumerGroups.ts b/src/explorer/models/consumerGroups.ts index 3b6a44b..091ecd1 100644 --- a/src/explorer/models/consumerGroups.ts +++ b/src/explorer/models/consumerGroups.ts @@ -2,8 +2,10 @@ import * as vscode from "vscode"; import { ConsumerGroupMember } from "../../client"; import { Icons } from "../../constants"; +import { getWorkspaceSettings } from "../../settings"; import { NodeBase } from "./nodeBase"; import { ClusterItem } from "./cluster"; +import * as minimatch from "minimatch"; export class ConsumerGroupsItem extends NodeBase { public label = "Consumer Groups"; @@ -16,13 +18,24 @@ export class ConsumerGroupsItem extends NodeBase { async computeChildren() : Promise { const client = this.getParent().client; - const consumerGroupIds = await client.getConsumerGroupIds(); + let consumerGroupIds = await client.getConsumerGroupIds(); + const settings = getWorkspaceSettings(); + consumerGroupIds = consumerGroupIds.filter(cg => this.isDisplayed(cg, settings.consumerFilters)); + return Promise.resolve( consumerGroupIds.map((consumerGroupId) => (new ConsumerGroupItem(consumerGroupId, this)))); } getParent(): ClusterItem { return super.getParent(); } + + private isDisplayed(consumerGroup: string, filters: string[]): boolean { + if (!filters) { + return true; + } + const id = consumerGroup.toLowerCase(); + return !filters.find( f => minimatch(id, f)); + } } class ConsumerGroupItem extends NodeBase { diff --git a/src/explorer/models/topics.ts b/src/explorer/models/topics.ts index 7be5a10..ca33397 100644 --- a/src/explorer/models/topics.ts +++ b/src/explorer/models/topics.ts @@ -7,6 +7,7 @@ import { TopicSortOption } from "../../settings/workspace"; import { ClusterItem } from "./cluster"; import { ConfigsItem } from "./common"; import { NodeBase } from "./nodeBase"; +import * as minimatch from "minimatch"; export class TopicGroupItem extends NodeBase { public label = "Topics"; @@ -21,6 +22,8 @@ export class TopicGroupItem extends NodeBase { const client = this.getParent().client; const settings = getWorkspaceSettings(); let topics = await client.getTopics(); + //Filter topics before sorting them + topics = topics.filter(t => this.isDisplayed(t, settings.topicFilters)); switch (settings.topicSortOption) { case TopicSortOption.Name: @@ -30,7 +33,6 @@ export class TopicGroupItem extends NodeBase { topics = topics.sort(this.sortByPartitionsAscending); break; } - return topics.map((topic) => { return new TopicItem(topic, this); }); @@ -50,6 +52,14 @@ export class TopicGroupItem extends NodeBase { if (a.partitionCount > b.partitionCount) { return 1; } return 0; } + + private isDisplayed(t: Topic, filters: string[]): boolean { + if (!filters) { + return true; + } + const id = t.id.toLowerCase(); + return !filters.find( f => minimatch(id, f)); + } } export class TopicItem extends NodeBase { diff --git a/src/settings/workspace.ts b/src/settings/workspace.ts index 396c929..a3c1f31 100644 --- a/src/settings/workspace.ts +++ b/src/settings/workspace.ts @@ -15,6 +15,8 @@ export enum TopicSortOption { export type InitialConsumerOffset = "latest" | "earliest"; const DEFAULT_PRODUCER_LOCALE = 'en'; +const DEFAULT_TOPIC_FILTER = ['__consumer_offsets', '__transaction_state', '_schemas']; +const DEFAULT_CONSUMER_FILTER:string[] = []; export interface WorkspaceSettings extends vscode.Disposable { consumerOffset: InitialConsumerOffset; @@ -35,6 +37,8 @@ class VsCodeWorkspaceSettings implements WorkspaceSettings { public topicSortOption: TopicSortOption = TopicSortOption.Name; public producerFakerJSEnabled = true; public producerFakerJSLocale = DEFAULT_PRODUCER_LOCALE; + public topicFilters = DEFAULT_TOPIC_FILTER; + public consumerFilters = DEFAULT_CONSUMER_FILTER; private constructor() { this.configurationChangeHandlerDisposable = vscode.workspace.onDidChangeConfiguration( @@ -56,6 +60,8 @@ class VsCodeWorkspaceSettings implements WorkspaceSettings { this.topicSortOption = configuration.get("explorer.topics.sort", TopicSortOption.Name); this.producerFakerJSEnabled = configuration.get("producers.fakerjs.enabled", true); this.producerFakerJSLocale = configuration.get("producers.fakerjs.locale", DEFAULT_PRODUCER_LOCALE); + this.topicFilters = configuration.get("explorer.topics.filter", DEFAULT_TOPIC_FILTER); + this.consumerFilters = configuration.get("explorer.consumers.filter", DEFAULT_CONSUMER_FILTER); } dispose(): void {