Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yanjun Zhou <zhouya@vmware.com>
  • Loading branch information
yanjunz97 committed Mar 9, 2022
1 parent 3dbc0d5 commit f93ae37
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,23 @@ jobs:
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push antrea/flow-aggregator:latest
check-clickhouse-monitor-changes:
name: Check whether flow-visibility-clickhouse-monitor image need to be built based on diff
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: antrea-io/has-changes@v1
id: check_diff
with:
args: build/yamls/* ci/* cmd/* docs/* hack/* multicluster/* pkg/* test/* third_party/* plugins/octant/* plugins/grafana-sankey-plugin/* *.md
outputs:
has_changes: ${{ steps.check_diff.outputs.has_changes }}

build-flow-visibility-clickhouse-monitor:
needs: check-changes
if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }}
needs: check-clickhouse-monitor-changes
if: ${{ needs.check-clickhouse-monitor-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }}
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 3 additions & 1 deletion build/yamls/flow-visibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4966,7 +4966,9 @@ spec:
- name: MV_NAMES
value: default.flows_pod_view default.flows_node_view default.flows_policy_view
- name: NAMESPACE
value: flow-visibility
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MONITOR_LABEL
value: app=clickhouse-monitor
image: projects.registry.vmware.com/antrea/flow-visibility-clickhouse-monitor:latest
Expand Down
4 changes: 3 additions & 1 deletion build/yamls/flow-visibility/base/clickhouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ spec:
- name: MV_NAMES
value: "default.flows_pod_view default.flows_node_view default.flows_policy_view"
- name: NAMESPACE
value: "flow-visibility"
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MONITOR_LABEL
value: "app=clickhouse-monitor"
restartPolicy: OnFailure
12 changes: 6 additions & 6 deletions plugins/flow-visibility/clickhouse-monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ func skipRound() bool {
// reads the number of rounds requires to be skipped
logs := strings.Split(logString, "skipRoundsNum=")
if len(logs) != 2 {
klog.ErrorS(nil, "Error in finding number of rounds")
klog.ErrorS(nil, "Error when finding number of rounds")
return false
}
lines := strings.Split(logs[1], "\n")
remainingRoundsNum, convErr := strconv.Atoi(lines[0])
if convErr != nil {
klog.ErrorS(convErr, "Error in finding last monitor job")
klog.ErrorS(convErr, "Error when finding last monitor job")
return false
}
if remainingRoundsNum > 0 {
Expand All @@ -123,12 +123,12 @@ func getPodLogs() (string, error) {
LabelSelector: monitorLabel,
}
if err != nil {
return logString, fmt.Errorf("error in getting config: %v", err)
return logString, fmt.Errorf("error when getting config: %v", err)
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return logString, fmt.Errorf("error in getting access to K8S: %v", err)
return logString, fmt.Errorf("error when getting access to K8S: %v", err)
}
// gets Clickhouse monitor pod
pods, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), listOptions)
Expand All @@ -141,14 +141,14 @@ func getPodLogs() (string, error) {
req := clientset.CoreV1().Pods(namespace).GetLogs(pod.Name, &podLogOpts)
podLogs, err := req.Stream(context.TODO())
if err != nil {
return logString, fmt.Errorf("error in opening stream: %v", err)
return logString, fmt.Errorf("error when opening stream: %v", err)
}
defer podLogs.Close()

buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
if err != nil {
return logString, fmt.Errorf("error in copy information from podLogs to buf: %v", err)
return logString, fmt.Errorf("error when copying information from podLogs to buf: %v", err)
}
logString := buf.String()
return logString, nil
Expand Down

0 comments on commit f93ae37

Please sign in to comment.