-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR added multicast statistics support for the following cases: - Supplements current networkpolicy statistics implementation by parsing multicast related flows, which can be displayed as kubectl get antreanetworkpolicystats multicast-networkpolicy-name. - Add a node-level antctl command antctl get multicaststats, showing inbound and outbound packet count for each pod interface. - Add an extra kubectl get multicastgroupmembers command. This command shows which pods have joined multicast group for the whole cluster. Signed-off-by: ceclinux <src655@gmail.com>
- Loading branch information
Showing
35 changed files
with
1,957 additions
and
159 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
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
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,78 @@ | ||
// 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 multicast | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strconv" | ||
|
||
"antrea.io/antrea/pkg/agent/interfacestore" | ||
"antrea.io/antrea/pkg/agent/multicast" | ||
"antrea.io/antrea/pkg/agent/querier" | ||
"antrea.io/antrea/pkg/antctl/transform/common" | ||
"antrea.io/antrea/pkg/features" | ||
) | ||
|
||
type Response struct { | ||
PodString string `json:"podString,omitempty"` | ||
Inbound string `json:"inbound,omitempty"` | ||
Outbound string `json:"outbound,omitempty"` | ||
} | ||
|
||
func generateResponse(iface *interfacestore.InterfaceConfig, trafficStats *multicast.PodTrafficStats) Response { | ||
return Response{ | ||
PodString: iface.PodNamespace + "/" + iface.PodName, | ||
Inbound: strconv.FormatInt(int64(trafficStats.Inbound), 10), | ||
Outbound: strconv.FormatInt(int64(trafficStats.Outbound), 10), | ||
} | ||
} | ||
|
||
// HandleFunc returns the function which can handle queries issued by 'antctl get multicaststats' command. | ||
// It will return per-pod multicast traffic statistics for the local node. | ||
func HandleFunc(aq querier.AgentQuerier) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
if !features.DefaultFeatureGate.Enabled(features.Multicast) { | ||
http.Error(w, "Multicast is not enabled", http.StatusServiceUnavailable) | ||
return | ||
} | ||
stats := aq.GetMulticastInfoQuerier().GetPerPodStats() | ||
responses := make([]Response, 0) | ||
for iface, trafficStats := range stats { | ||
if trafficStats.Inbound == 0 && trafficStats.Outbound == 0 { | ||
continue | ||
} | ||
responses = append(responses, generateResponse(iface, trafficStats)) | ||
} | ||
err := json.NewEncoder(w).Encode(responses) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} | ||
} | ||
} | ||
|
||
var _ common.TableOutput = new(Response) | ||
|
||
func (r Response) GetTableHeader() []string { | ||
return []string{"POD", "INBOUND", "OUTBOUND"} | ||
} | ||
|
||
func (r Response) GetTableRow(_ int) []string { | ||
return []string{r.PodString, r.Inbound, r.Outbound} | ||
} | ||
|
||
func (r Response) SortRows() bool { | ||
return true | ||
} |
Oops, something went wrong.