-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'update disable' for clickhouse and flow-collector
Signed-off-by: Yun-Tang Hsu <hsuy@hsuy-a01.vmware.com>
- Loading branch information
Yun-Tang Hsu
committed
Apr 15, 2022
1 parent
df0f3e2
commit 9467396
Showing
6 changed files
with
170 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2020 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 update | ||
|
||
import ( | ||
"antrea.io/antrea/pkg/flowaggregator/querier" | ||
"antrea.io/antrea/pkg/util/flowexport" | ||
"net" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
const ( | ||
defaultExternalFlowCollectorTransport = "tcp" | ||
defaultExternalFlowCollectorPort = "4739" | ||
) | ||
|
||
// HandleFunc returns the function which can handle the /update API request. | ||
func HandleFunc(faq querier.FlowAggregatorQuerier) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
enableFlowCollector := r.URL.Query().Get("enable") | ||
if enableFlowCollector != "" { | ||
if enableFlowCollector == "clickhouse" { | ||
faq.EnableDefaultClickHouse() | ||
} | ||
} | ||
disableFlowCollector := r.URL.Query().Get("disable") | ||
if disableFlowCollector != "" { | ||
if disableFlowCollector == "clickhouse" { | ||
if err := faq.DisableClickHouse(); err != nil { | ||
http.Error(w, "Error when disable clickhouse: "+err.Error(), http.StatusNotFound) | ||
} | ||
} else if disableFlowCollector == "flow-collector" { | ||
if err := faq.DisableFlowCollector(); err != nil { | ||
http.Error(w, "Error when disable Flow-collector: "+err.Error(), http.StatusNotFound) | ||
} | ||
} | ||
} | ||
externalFlowCollectorAddr := r.URL.Query().Get("externalflowcollectoraddr") | ||
if externalFlowCollectorAddr != "" { | ||
host, port, proto, err := flowexport.ParseFlowCollectorAddr(externalFlowCollectorAddr, defaultExternalFlowCollectorPort, defaultExternalFlowCollectorTransport) | ||
if err != nil { | ||
http.Error(w, "Error when parsing externalFlowCollectorAddr: "+err.Error(), http.StatusNotFound) | ||
} | ||
faq.SetExternalFlowCollectorAddr(querier.ExternalFlowCollectorAddr{ | ||
Address: net.JoinHostPort(host, port), | ||
Protocol: proto, | ||
}) | ||
} | ||
var sb strings.Builder | ||
updateDataBase := r.URL.Query().Get("database") | ||
if updateDataBase != "" { | ||
sb.WriteString("&database=") | ||
sb.WriteString(updateDataBase) | ||
} | ||
updateDataBaseURL := r.URL.Query().Get("databaseURL") | ||
if updateDataBaseURL != "" { | ||
sb.WriteString("&databaseURL=") | ||
sb.WriteString(updateDataBaseURL) | ||
} | ||
updateDebug := r.URL.Query().Get("debug") | ||
if updateDebug != "" { | ||
sb.WriteString("&debug=") | ||
sb.WriteString(updateDebug) | ||
} | ||
updateCompress := r.URL.Query().Get("compress") | ||
if updateCompress != "" { | ||
sb.WriteString("&compress=") | ||
sb.WriteString(updateCompress) | ||
} | ||
updateCommitInterval := r.URL.Query().Get("commitInterval") | ||
if updateCommitInterval != "" { | ||
sb.WriteString("&commitInterval=") | ||
sb.WriteString(updateCommitInterval) | ||
} | ||
if sb.Len() != 0 { | ||
faq.UpdateClickHouse(sb.String()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters