Skip to content

Commit

Permalink
Add CLI command to retrieve metrics in clickhouse database
Browse files Browse the repository at this point in the history
1. Add CLI commands to get diagnostic infos about Clickhouse DB
2. Add e2e test for theia CLI

Signed-off-by: Yun-Tang Hsu <hsuy@vmware.com>
  • Loading branch information
yuntanghsu committed Aug 5, 2022
1 parent 3e15d4e commit e02f3a4
Show file tree
Hide file tree
Showing 19 changed files with 928 additions and 94 deletions.
2 changes: 2 additions & 0 deletions ci/jenkins/test-vmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ function deliver_antrea {

${GIT_CHECKOUT_DIR}/hack/generate-manifest.sh --ch-size 100Mi --ch-monitor-threshold 0.1 > ${GIT_CHECKOUT_DIR}/build/yamls/flow-visibility.yml
${GIT_CHECKOUT_DIR}/hack/generate-manifest.sh --no-grafana --spark-operator > ${GIT_CHECKOUT_DIR}/build/yamls/flow-visibility-with-spark.yml
${GIT_CHECKOUT_DIR}/hack/generate-manifest.sh --no-grafana > ${GIT_CHECKOUT_DIR}/build/yamls/flow-visibility-ch-only.yml


${SCP_WITH_ANTREA_CI_KEY} $GIT_CHECKOUT_DIR/build/charts/theia/crds/clickhouse-operator-install-bundle.yaml capv@${control_plane_ip}:~
${SCP_WITH_ANTREA_CI_KEY} $GIT_CHECKOUT_DIR/build/yamls/*.yml capv@${control_plane_ip}:~
Expand Down
2 changes: 2 additions & 0 deletions ci/kind/test-e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TESTBED_CMD=$(dirname $0)"/kind-setup.sh"
YML_DIR=$(dirname $0)"/../../build/yamls"
FLOW_VISIBILITY_CMD=$(dirname $0)"/../../hack/generate-manifest.sh --ch-size 100Mi --ch-monitor-threshold 0.1"
FLOW_VISIBILITY_WITH_SPARK_CMD=$(dirname $0)"/../../hack/generate-manifest.sh --no-grafana --spark-operator"
FLOW_VISIBILITY_CH_ONLY_CMD=$(dirname $0)"/../../hack/generate-manifest.sh --no-grafana"
CH_OPERATOR_YML=$(dirname $0)"/../../build/charts/theia/crds/clickhouse-operator-install-bundle.yaml"

make theia-linux
Expand Down Expand Up @@ -161,6 +162,7 @@ function run_test {
docker exec -i kind-control-plane dd of=/root/clickhouse-operator-install-bundle.yaml < $CH_OPERATOR_YML
$FLOW_VISIBILITY_CMD | docker exec -i kind-control-plane dd of=/root/flow-visibility.yml
$FLOW_VISIBILITY_WITH_SPARK_CMD | docker exec -i kind-control-plane dd of=/root/flow-visibility-with-spark.yml
$FLOW_VISIBILITY_CH_ONLY_CMD | docker exec -i kind-control-plane dd of=/root/flow-visibility-ch-only.yml

docker exec -i kind-control-plane dd of=/root/theia < $THEIACTL_BIN

Expand Down
81 changes: 79 additions & 2 deletions docs/theia-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ visibility capabilities.
<!-- toc -->
- [Installation](#installation)
- [Usage](#usage)
- [NetworkPolicy Recommendation feature](#networkpolicy-recommendation-feature)
- [ClickHouse](#clickhouse)
- [Disk usage information](#disk-usage-information)
- [Table Information](#table-information)
- [Insertion rate](#insertion-rate)
- [Stack trace](#stack-trace)
<!-- /toc -->

## Installation
Expand Down Expand Up @@ -36,8 +42,11 @@ theia help

## Usage

To see the list of available commands and options, run `theia help`. Currently,
we have 5 commands for the NetworkPolicy Recommendation feature:
To see the list of available commands and options, run `theia help`.

### NetworkPolicy Recommendation feature

We currently have 5 commands for NetworkPolicy Recommendation:

- `theia policy-recommendation run`
- `theia policy-recommendation status`
Expand All @@ -47,3 +56,71 @@ we have 5 commands for the NetworkPolicy Recommendation feature:

For details, please refer to [NetworkPolicy recommendation doc](
networkpolicy-recommendation.md)

### ClickHouse

From Theia v0.2, we introduce one command for ClickHouse:

- `theia clickhouse status [flags]`

#### Disk usage information

The `--diskInfo` flag will list disk usage information of each ClickHouse shard. `Shard`, `DatabaseName`, `Path`, `Free`
, `Total` and `Used_Percentage`of each ClickHouse shard will be displayed in table format. For example:

```bash
> theia clickhouse status --diskInfo
Shard DatabaseName Path Free Total Used_Percentage
1 default /var/lib/clickhouse/ 1.84 GiB 1.84 GiB 0.04 %
```

#### Table Information

The `--tableInfo` flag will list basic table information of each ClickHouse shard. `Shard`, `DatabaseName`, `TableName`,
`TotalRows`, `TotalBytes` and `TotalCol`of tables in each ClickHouse shard will be displayed in table format. For example:

```bash
> theia clickhouse status --tableInfo
Shard DatabaseName TableName TotalRows TotalBytes TotalCols
1 default .inner.flows_node_view 7 2.84 KiB 16
1 default .inner.flows_pod_view 131 5.00 KiB 20
1 default .inner.flows_policy_view 131 6.28 KiB 27
1 default flows 267 18.36 KiB 49
```

#### Insertion rate

The `--insertRate` flag will list the insertion rate of each ClickHouse shard. `Shard`, `RowsPerSecond`, and
`BytesPerSecond` of each ClickHouse shard will be displayed in table format. For example:

```bash
> theia clickhouse status --insertRate
Shard RowsPerSecond BytesPerSecond
1 230 6.31 KiB
```

#### Stack trace

If ClickHouse is busy with something, and you don’t know what’s happening, you can check the stacktraces of all
the threads which are working.

The `--stackTraces` flag will list the stacktraces of each ClickHouse shard. `Shard`, `trace_function`, and
`count()` of each ClickHouse shard will be displayed in table format. For example:

```bash
> theia clickhouse status --stackTraces
Row 1:
-------
Shard: 1
trace_functions: pthread_cond_timedwait@@GLIBC_2.3.2\nPoco::EventImpl::waitImpl(long)\nPoco::NotificationQueue::
waitDequeueNotification(long)\nDB::BackgroundSchedulePool::threadFunction()\n\nThreadPoolImpl<std::__1::thread>::
worker(std::__1::__list_iterator<std::__1::thread, void*>)\n\nstart_thread\n__clone
count(): 128

Row 2:
-------
Shard: 1
trace_functions: __poll\nPoco::Net::SocketImpl::pollImpl(Poco::Timespan&, int)\nPoco::Net::SocketImpl::poll(Poco::
Timespan const&, int)\nPoco::Net::TCPServer::run()\nPoco::ThreadImpl::runnableEntry(void*)\nstart_thread\n__clone
count(): 5
```
44 changes: 44 additions & 0 deletions pkg/theia/commands/clickhouse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2022 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package commands

import (
"fmt"

"github.com/spf13/cobra"
)

var clickHouseCmd = &cobra.Command{
Use: "clickhouse",
Aliases: []string{"ch"},
Short: "Commands of Theia ClickHouse feature",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Error: must also specify a subcommand to run like status")
},
}

func init() {
rootCmd.AddCommand(clickHouseCmd)
clickHouseCmd.PersistentFlags().String(
"clickhouse-endpoint",
"",
"The ClickHouse service endpoint.")
clickHouseCmd.PersistentFlags().Bool(
"use-cluster-ip",
false,
`Enable this option will use ClusterIP instead of port forwarding when connecting to the ClickHouse Service.
It can only be used when running in cluster.`,
)
}
Loading

0 comments on commit e02f3a4

Please sign in to comment.