Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix host network pod ping fail #164

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 98 additions & 89 deletions pkg/controller/rpc/controller.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/controller/rpc/controller.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ message Task {
message PodInfo {
string name = 1;
string namespace = 2;
bool hostNetwork = 3;
}

message NodeInfo {
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/rpc/controller_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/controller/service/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ func (c *controller) getPodInfo(ctx context.Context, podNamespace, podName strin
return nil, nil, "", fmt.Errorf("pod %s/%s is not running", podNamespace, podName)
}
pi := &rpc.PodInfo{
Name: podName,
Namespace: podNamespace,
Name: podName,
Namespace: podNamespace,
HostNetwork: p.Spec.HostNetwork,
}
ni := &rpc.NodeInfo{
Name: p.Spec.NodeName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/task-agent/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type capture struct {
}

func (a *Agent) generateCaptures(id string, task *rpc.CaptureInfo) ([]capture, error) {
if task.Pod != nil {
if task.Pod != nil && !task.Pod.HostNetwork {
var podEntry *nettop.Entity
entries := nettop.GetAllEntity()
for _, e := range entries {
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/task-agent/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func getLatency(pingResult string) (float64, float64, float64, error) {

func (a *Agent) ping(task *rpc.PingInfo) (string, error) {
var pingCmd string
if task.Pod != nil {
if task.Pod != nil && !task.Pod.HostNetwork {
var podEntry *nettop.Entity
entries := nettop.GetAllEntity()
for _, e := range entries {
Expand Down
9 changes: 8 additions & 1 deletion webui/src/pages/pingmesh/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Card, Message} from "@alifd/next"
import {Card, Icon, Message} from "@alifd/next"
import PageHeader from "@/components/PageHeader"
import {useState} from "react";
import PingForm from "@/pages/pingmesh/pingForm";
Expand All @@ -9,6 +9,7 @@ import { definePageConfig } from "ice";

export default function Capture() {
const [latency, setLatency] = useState()
const [detecting, setDetecting] = useState(false)

return (
<div>
Expand All @@ -19,7 +20,10 @@ export default function Capture() {
<Card id="card-capture" title="Detect" contentHeight="auto">
<Card.Content>
<PingForm onSubmit={(values) => {
setDetecting(true)
setLatency(undefined)
pingMeshService.pingMeshLatency(values).then(res => {
setDetecting(false)
setLatency(res)
}).catch(err => {
Message.error(`error get ping mesh result:${getErrorMessage(err)}`)
Expand All @@ -28,6 +32,9 @@ export default function Capture() {
</Card.Content>
</Card>
<Card id="card-capture-tasks" title="Result" contentHeight="auto">
<Card.Content>
{detecting && <span style={{color: 'orange', fontSize: 20}}> <Icon size="xs" type="loading" />Latency Detecting</span>}
</Card.Content>
<Card.Content>
{latency && <PingGraph data={latency}/>}
</Card.Content>
Expand Down
20 changes: 12 additions & 8 deletions webui/src/pages/pingmesh/pingGraph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const toGraphData = (data: any): GraphData => {
id: item.id,
source: nodeID(item.source),
target: nodeID(item.destination),
latency_avg: item.latency_avg.toFixed(3),
latency_max: item.latency_max.toFixed(3),
latency_min: item.latency_min.toFixed(3),
latency_avg: item.latency_avg < 9000? item.latency_avg.toFixed(3) : "failed",
latency_max: item.latency_max < 9000? item.latency_max.toFixed(3) : "failed",
latency_min: item.latency_min < 9000? item.latency_min.toFixed(3) : "failed",
curvature: 0.3,
}
});
Expand All @@ -72,13 +72,14 @@ const PingGraph: React.FC<PingGraphProps> = (props: PingGraphProps): JSX.Element
}, []);
return (
<div style={{
position: "relative",
height: "400px",
width: "900px",
width: "1000px",
display: "inline-flex",
}}>
<div style={{
height: "400px",
width: "600px",
width: "1000px",
}}>
<ForceGraph2D ref={ref} graphData={graphData}
linkCurveRotation="rotation"
Expand All @@ -87,7 +88,7 @@ const PingGraph: React.FC<PingGraphProps> = (props: PingGraphProps): JSX.Element
linkDirectionalParticles={2}
linkCurvature={0.3}
nodeRelSize={6}
width={600}
width={1000}
height={400}
enableNodeDrag={true}
onNodeDragEnd={node => {
Expand All @@ -108,6 +109,9 @@ const PingGraph: React.FC<PingGraphProps> = (props: PingGraphProps): JSX.Element
linkCanvasObjectMode={() => 'after'}
linkLabel={(link) => `${link.source.name}->${link.target.name} max/avg/min ${link.latency_max}/${link.latency_avg}/${link.latency_min} ms`}
linkColor={(link) => {
if (link.latency_avg === "failed") {
return 'red'
}
return link.latency_avg > 1 ? (link.latency_avg > 100 ? 'red' : 'orange') : 'green'
}}
linkCanvasObject={(link, ctx) => {
Expand Down Expand Up @@ -145,7 +149,7 @@ const PingGraph: React.FC<PingGraphProps> = (props: PingGraphProps): JSX.Element
// maintain label vertical orientation for legibility
if (textAngle > Math.PI / 2) textAngle = -(Math.PI - textAngle);
if (textAngle < -Math.PI / 2) textAngle = -(-Math.PI - textAngle);
const label = `${link.latency_avg}ms`;
const label = link.latency_avg==="failed"? "failed" : `${link.latency_avg}ms`;
// estimate fontSize to fit in link length
ctx.font = '1px Sans-Serif';
const fontSize = Math.min(MAX_FONT_SIZE, maxTextLength / ctx.measureText(label).width);
Expand All @@ -167,7 +171,7 @@ const PingGraph: React.FC<PingGraphProps> = (props: PingGraphProps): JSX.Element
}}
/>
</div>
<div style={{float: 'right', width: '200px', display: 'inline-block'}}>
<div style={{float: 'right', width: '200px', position: 'absolute', top: '0px', right: '0px'}}>
<div><span style={{color: 'red'}}>--- </span><span>latency &gt; 100ms or failed</span></div>
<div><span style={{color: 'orange'}}>--- </span><span>1ms &lt; latency &lt; 100ms</span></div>
<div><span style={{color: 'green'}}>--- </span><span>latency &lt; 1ms</span></div>
Expand Down
Loading