• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang report.MakeNode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/weaveworks/scope/report.MakeNode函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeNode函数的具体用法?Golang MakeNode怎么用?Golang MakeNode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MakeNode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: BenchmarkNodeSetMerge

func BenchmarkNodeSetMerge(b *testing.B) {
	n, other := report.NodeSet{}, report.NodeSet{}
	for i := 0; i < 600; i++ {
		n = n.Add(
			report.MakeNode().WithID(fmt.Sprint(i)).WithLatests(map[string]string{
				"a": "1",
				"b": "2",
			}),
		)
	}

	for i := 400; i < 1000; i++ {
		other = other.Add(
			report.MakeNode().WithID(fmt.Sprint(i)).WithLatests(map[string]string{
				"c": "1",
				"d": "2",
			}),
		)
	}
	b.ReportAllocs()
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		benchmarkResult = n.Merge(other)
	}
}
开发者ID:pauloheck,项目名称:scope,代码行数:26,代码来源:node_set_test.go


示例2: TestCollector

func TestCollector(t *testing.T) {
	window := time.Millisecond
	c := xfer.NewCollector(window)

	r1 := report.MakeReport()
	r1.Endpoint.Nodes["foo"] = report.MakeNode()

	r2 := report.MakeReport()
	r2.Endpoint.Nodes["bar"] = report.MakeNode()

	if want, have := report.MakeReport(), c.Report(); !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}

	c.Add(r1)
	if want, have := r1, c.Report(); !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}

	c.Add(r2)

	merged := report.MakeReport()
	merged = merged.Merge(r1)
	merged = merged.Merge(r2)
	if want, have := merged, c.Report(); !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
开发者ID:philipz,项目名称:scope,代码行数:28,代码来源:collector_test.go


示例3: TestMergeRenderableNode

func TestMergeRenderableNode(t *testing.T) {
	node1 := render.RenderableNode{
		ID:         "foo",
		LabelMajor: "",
		LabelMinor: "minor",
		Rank:       "",
		Pseudo:     false,
		Node:       report.MakeNode().WithAdjacent("a1"),
		Origins:    report.MakeIDList("o1"),
	}
	node2 := render.RenderableNode{
		ID:         "foo",
		LabelMajor: "major",
		LabelMinor: "",
		Rank:       "rank",
		Pseudo:     false,
		Node:       report.MakeNode().WithAdjacent("a2"),
		Origins:    report.MakeIDList("o2"),
	}
	want := render.RenderableNode{
		ID:           "foo",
		LabelMajor:   "major",
		LabelMinor:   "minor",
		Rank:         "rank",
		Pseudo:       false,
		Node:         report.MakeNode().WithAdjacency(report.MakeIDList("a1", "a2")),
		Origins:      report.MakeIDList("o1", "o2"),
		EdgeMetadata: report.EdgeMetadata{},
	}
	have := node1.Merge(node2)
	if !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
开发者ID:philipz,项目名称:scope,代码行数:34,代码来源:renderable_node_test.go


示例4: TestNode

func TestNode(t *testing.T) {
	{
		node := report.MakeNode().WithLatests(map[string]string{
			"foo": "bar",
		})
		if v, _ := node.Latest.Lookup("foo"); v != "bar" {
			t.Errorf("want foo, have %s", v)
		}
	}
	{
		node := report.MakeNode().WithCounters(
			map[string]int{"foo": 1},
		)
		if value, _ := node.Counters.Lookup("foo"); value != 1 {
			t.Errorf("want foo, have %d", value)
		}
	}
	{
		node := report.MakeNode().WithAdjacent("foo")
		if node.Adjacency[0] != "foo" {
			t.Errorf("want foo, have %v", node.Adjacency)
		}
	}
	{
		node := report.MakeNode().WithEdge("foo", report.EdgeMetadata{
			EgressPacketCount: newu64(13),
		})
		if node.Adjacency[0] != "foo" {
			t.Errorf("want foo, have %v", node.Adjacency)
		}
		if v, ok := node.Edges.Lookup("foo"); ok && *v.EgressPacketCount != 13 {
			t.Errorf("want 13, have %v", node.Edges)
		}
	}
}
开发者ID:pauloheck,项目名称:scope,代码行数:35,代码来源:report_test.go


示例5: TestNode

func TestNode(t *testing.T) {
	{
		node := report.MakeNode().WithMetadata(report.Metadata{
			"foo": "bar",
		})
		if node.Metadata["foo"] != "bar" {
			t.Errorf("want foo, have %s", node.Metadata["foo"])
		}
	}
	{
		node := report.MakeNode().WithCounters(report.Counters{
			"foo": 1,
		})
		if node.Counters["foo"] != 1 {
			t.Errorf("want foo, have %d", node.Counters["foo"])
		}
	}
	{
		node := report.MakeNode().WithAdjacent("foo")
		if node.Adjacency[0] != "foo" {
			t.Errorf("want foo, have %v", node.Adjacency)
		}
	}
	{
		node := report.MakeNode().WithEdge("foo", report.EdgeMetadata{
			EgressPacketCount: newu64(13),
		})
		if node.Adjacency[0] != "foo" {
			t.Errorf("want foo, have %v", node.Adjacency)
		}
		if *node.Edges["foo"].EgressPacketCount != 13 {
			t.Errorf("want 13, have %v", node.Edges)
		}
	}
}
开发者ID:rnd-ua,项目名称:scope,代码行数:35,代码来源:report_test.go


示例6: TestApply

func TestApply(t *testing.T) {
	var (
		endpointNodeID = "c"
		addressNodeID  = "d"
		endpointNode   = report.MakeNodeWith(map[string]string{"5": "6"})
		addressNode    = report.MakeNodeWith(map[string]string{"7": "8"})
	)

	p := New(0, 0, nil)
	p.AddTagger(NewTopologyTagger())

	r := report.MakeReport()
	r.Endpoint.AddNode(endpointNodeID, endpointNode)
	r.Address.AddNode(addressNodeID, addressNode)
	r = p.tag(r)

	for _, tuple := range []struct {
		want report.Node
		from report.Topology
		via  string
	}{
		{endpointNode.Merge(report.MakeNode().WithID("c").WithTopology(report.Endpoint)), r.Endpoint, endpointNodeID},
		{addressNode.Merge(report.MakeNode().WithID("d").WithTopology(report.Address)), r.Address, addressNodeID},
	} {
		if want, have := tuple.want, tuple.from.Nodes[tuple.via]; !reflect.DeepEqual(want, have) {
			t.Errorf("want %+v, have %+v", want, have)
		}
	}
}
开发者ID:pauloheck,项目名称:scope,代码行数:29,代码来源:probe_internal_test.go


示例7: Report

// Report implements Reporter.
func (r *Reporter) Report() (report.Report, error) {
	defer func(begin time.Time) {
		SpyDuration.WithLabelValues().Observe(float64(time.Since(begin)))
	}(time.Now())

	hostNodeID := report.MakeHostNodeID(r.hostID)
	rpt := report.MakeReport()

	{
		conns, err := procspy.Connections(r.includeProcesses)
		if err != nil {
			return rpt, err
		}
		commonNodeInfo := report.MakeNode().WithMetadata(report.Metadata{
			Procspied: "true",
		})
		for conn := conns.Next(); conn != nil; conn = conns.Next() {
			var (
				localPort  = conn.LocalPort
				remotePort = conn.RemotePort
				localAddr  = conn.LocalAddress.String()
				remoteAddr = conn.RemoteAddress.String()
			)
			extraNodeInfo := commonNodeInfo.Copy()
			if conn.Proc.PID > 0 {
				extraNodeInfo = extraNodeInfo.WithMetadata(report.Metadata{
					process.PID:       strconv.FormatUint(uint64(conn.Proc.PID), 10),
					report.HostNodeID: hostNodeID,
				})
			}
			r.addConnection(&rpt, localAddr, remoteAddr, localPort, remotePort, &extraNodeInfo, &commonNodeInfo)
		}
	}

	if r.conntracker != nil {
		extraNodeInfo := report.MakeNode().WithMetadata(report.Metadata{
			Conntracked: "true",
		})
		r.conntracker.WalkFlows(func(f Flow) {
			var (
				localPort  = uint16(f.Original.Layer4.SrcPort)
				remotePort = uint16(f.Original.Layer4.DstPort)
				localAddr  = f.Original.Layer3.SrcIP
				remoteAddr = f.Original.Layer3.DstIP
			)
			r.addConnection(&rpt, localAddr, remoteAddr, localPort, remotePort, &extraNodeInfo, &extraNodeInfo)
		})
	}

	if r.natmapper != nil {
		r.natmapper.ApplyNAT(rpt, r.hostID)
	}

	return rpt, nil
}
开发者ID:webwurst,项目名称:scope,代码行数:56,代码来源:reporter.go


示例8: TestMerge

func TestMerge(t *testing.T) {
	var (
		hostID = "xyz"
		src    = newMockSource([]byte{}, nil)
		on     = time.Millisecond
		off    = time.Millisecond
		rpt    = report.MakeReport()
		p      = sniff.Packet{
			SrcIP:     "1.0.0.0",
			SrcPort:   "1000",
			DstIP:     "2.0.0.0",
			DstPort:   "2000",
			Network:   512,
			Transport: 256,
		}

		_, ipnet, _ = net.ParseCIDR(p.SrcIP + "/24") // ;)
		localNets   = report.Networks([]*net.IPNet{ipnet})
	)
	sniff.New(hostID, localNets, src, on, off).Merge(p, &rpt)

	var (
		srcEndpointNodeID = report.MakeEndpointNodeID(hostID, p.SrcIP, p.SrcPort)
		dstEndpointNodeID = report.MakeEndpointNodeID(hostID, p.DstIP, p.DstPort)
	)
	if want, have := (report.Topology{
		Nodes: report.Nodes{
			srcEndpointNodeID: report.MakeNode().WithEdge(dstEndpointNodeID, report.EdgeMetadata{
				EgressPacketCount: newu64(1),
				EgressByteCount:   newu64(256),
			}),
			dstEndpointNodeID: report.MakeNode(),
		},
	}), rpt.Endpoint; !reflect.DeepEqual(want, have) {
		t.Errorf("%s", test.Diff(want, have))
	}

	var (
		srcAddressNodeID = report.MakeAddressNodeID(hostID, p.SrcIP)
		dstAddressNodeID = report.MakeAddressNodeID(hostID, p.DstIP)
	)
	if want, have := (report.Topology{
		Nodes: report.Nodes{
			srcAddressNodeID: report.MakeNode().WithEdge(dstAddressNodeID, report.EdgeMetadata{
				EgressPacketCount: newu64(1),
				EgressByteCount:   newu64(512),
			}),
			dstAddressNodeID: report.MakeNode(),
		},
	}), rpt.Address; !reflect.DeepEqual(want, have) {
		t.Errorf("%s", test.Diff(want, have))
	}
}
开发者ID:rnd-ua,项目名称:scope,代码行数:53,代码来源:sniffer_test.go


示例9: TestNodeSetDelete

func TestNodeSetDelete(t *testing.T) {
	for _, testcase := range []struct {
		input report.NodeSet
		nodes []string
		want  report.NodeSet
	}{
		{
			input: report.NodeSet{},
			nodes: []string{},
			want:  report.NodeSet{},
		},
		{
			input: report.EmptyNodeSet,
			nodes: []string{},
			want:  report.EmptyNodeSet,
		},
		{
			input: report.MakeNodeSet(report.MakeNode("a")),
			nodes: []string{},
			want:  report.MakeNodeSet(report.MakeNode("a")),
		},
		{
			input: report.EmptyNodeSet,
			nodes: []string{"a"},
			want:  report.EmptyNodeSet,
		},
		{
			input: report.MakeNodeSet(report.MakeNode("a")),
			nodes: []string{"a"},
			want:  report.EmptyNodeSet,
		},
		{
			input: report.MakeNodeSet(report.MakeNode("b")),
			nodes: []string{"a", "b"},
			want:  report.EmptyNodeSet,
		},
		{
			input: report.MakeNodeSet(report.MakeNode("a")),
			nodes: []string{"c", "b"},
			want:  report.MakeNodeSet(report.MakeNode("a")),
		},
		{
			input: report.MakeNodeSet(report.MakeNode("a"), report.MakeNode("c")),
			nodes: []string{"a", "a", "a"},
			want:  report.MakeNodeSet(report.MakeNode("c")),
		},
	} {
		originalLen := testcase.input.Size()
		if want, have := testcase.want, testcase.input.Delete(testcase.nodes...); !reflect.DeepEqual(want, have) {
			t.Errorf("%v + %v: want %v, have %v", testcase.input, testcase.nodes, want, have)
		}
		if testcase.input.Size() != originalLen {
			t.Errorf("%v + %v: modified the original input!", testcase.input, testcase.nodes)
		}
	}
}
开发者ID:CNDonny,项目名称:scope,代码行数:56,代码来源:node_set_test.go


示例10: TestMakeRenderableNodes

func TestMakeRenderableNodes(t *testing.T) {

	var (
		newu64     = func(value uint64) *uint64 { return &value }
		srcNodeID  = "srcNode"
		dstNode1ID = "dstNode1"
		dstNode2ID = "dstNode2"
		srcNode    = report.MakeNode().
				WithEdge(dstNode1ID, report.EdgeMetadata{EgressPacketCount: newu64(100), EgressByteCount: newu64(1000)}).
				WithEdge(dstNode2ID, report.EdgeMetadata{EgressPacketCount: newu64(200), EgressByteCount: newu64(2000)})
		dstNode1 = report.MakeNode()
		dstNode2 = report.MakeNode()
		topology = report.MakeTopology().
				AddNode(srcNodeID, srcNode).
				AddNode(dstNode1ID, dstNode1).
				AddNode(dstNode2ID, dstNode2)
	)

	result := render.MakeRenderableNodes(topology)
	mustLookup := func(id string) render.RenderableNode {
		node, ok := result[id]
		if !ok {
			t.Fatalf("Expected result to contain node: %q, got: %v", id, result)
		}
		return node
	}

	// Source nodes should have the flattened edge metadata
	{
		have := mustLookup(srcNodeID).EdgeMetadata
		want := report.EdgeMetadata{EgressPacketCount: newu64(300), EgressByteCount: newu64(3000)}
		if !reflect.DeepEqual(want, have) {
			t.Errorf(test.Diff(want, have))
		}
	}

	// Result destination nodes should have the reverse of the source nodes
	{
		have := mustLookup(dstNode1ID).EdgeMetadata
		want := report.EdgeMetadata{IngressPacketCount: newu64(100), IngressByteCount: newu64(1000)}
		if !reflect.DeepEqual(want, have) {
			t.Errorf(test.Diff(want, have))
		}

		have = mustLookup(dstNode2ID).EdgeMetadata
		want = report.EdgeMetadata{IngressPacketCount: newu64(200), IngressByteCount: newu64(2000)}
		if !reflect.DeepEqual(want, have) {
			t.Errorf(test.Diff(want, have))
		}
	}
}
开发者ID:pauloheck,项目名称:scope,代码行数:51,代码来源:selectors_test.go


示例11: TestReduceRender

func TestReduceRender(t *testing.T) {
	renderer := render.Reduce([]render.Renderer{
		mockRenderer{Nodes: report.Nodes{"foo": report.MakeNode("foo")}},
		mockRenderer{Nodes: report.Nodes{"bar": report.MakeNode("bar")}},
	})

	want := report.Nodes{
		"foo": report.MakeNode("foo"),
		"bar": report.MakeNode("bar"),
	}
	have := renderer.Render(report.MakeReport(), FilterNoop)
	if !reflect.DeepEqual(want, have) {
		t.Errorf("want %+v, have %+v", want, have)
	}
}
开发者ID:CNDonny,项目名称:scope,代码行数:15,代码来源:render_test.go


示例12: Report

// Report implements Reporter.
func (w *Weave) Report() (report.Report, error) {
	w.mtx.RLock()
	defer w.mtx.RUnlock()

	r := report.MakeReport()
	r.Container = r.Container.WithMetadataTemplates(report.MetadataTemplates{
		WeaveMACAddress:  {ID: WeaveMACAddress, Label: "Weave MAC", From: report.FromLatest, Priority: 17},
		WeaveDNSHostname: {ID: WeaveDNSHostname, Label: "Weave DNS Name", From: report.FromLatest, Priority: 18},
	})
	for _, peer := range w.statusCache.Router.Peers {
		r.Overlay.AddNode(report.MakeNodeWith(report.MakeOverlayNodeID(peer.Name), map[string]string{
			WeavePeerName:     peer.Name,
			WeavePeerNickName: peer.NickName,
		}))

	}
	if w.statusCache.IPAM.DefaultSubnet != "" {
		r.Overlay.AddNode(
			report.MakeNode(report.MakeOverlayNodeID(w.statusCache.Router.Name)).WithSets(
				report.MakeSets().Add(host.LocalNetworks, report.MakeStringSet(w.statusCache.IPAM.DefaultSubnet)),
			),
		)
	}
	return r, nil
}
开发者ID:CNDonny,项目名称:scope,代码行数:26,代码来源:weave.go


示例13: TestMapHostIdentity

func TestMapHostIdentity(t *testing.T) {
	for _, input := range []testcase{
		{nrn(report.MakeNode()), true}, // TODO it's questionable if this is actually correct
	} {
		testMap(t, render.MapHostIdentity, input)
	}
}
开发者ID:philipz,项目名称:scope,代码行数:7,代码来源:mapping_test.go


示例14: TestFilterRender

func TestFilterRender(t *testing.T) {
	renderer := render.FilterUnconnected(
		mockRenderer{RenderableNodes: render.RenderableNodes{
			"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("bar")},
			"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("foo")},
			"baz": {ID: "baz", Node: report.MakeNode()},
		}})
	want := render.RenderableNodes{
		"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("bar")},
		"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("foo")},
	}
	have := renderer.Render(report.MakeReport()).Prune()
	if !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
开发者ID:hrhelena,项目名称:scope,代码行数:16,代码来源:filters_test.go


示例15: TestMakeNodeSet

func TestMakeNodeSet(t *testing.T) {
	for _, testcase := range []struct {
		inputs []string
		wants  []string
	}{
		{inputs: nil, wants: nil},
		{
			inputs: []string{"a"},
			wants:  []string{"a"},
		},
		{
			inputs: []string{"b", "c", "a"},
			wants:  []string{"a", "b", "c"},
		},
		{
			inputs: []string{"a", "a", "a"},
			wants:  []string{"a"},
		},
	} {
		var inputs []report.Node
		for _, id := range testcase.inputs {
			inputs = append(inputs, report.MakeNode(id))
		}
		set := report.MakeNodeSet(inputs...)
		var have []string
		set.ForEach(func(node report.Node) { have = append(have, node.ID) })
		if !reflect.DeepEqual(testcase.wants, have) {
			t.Errorf("%#v: want %#v, have %#v", testcase.inputs, testcase.wants, have)
		}
	}
}
开发者ID:CNDonny,项目名称:scope,代码行数:31,代码来源:node_set_test.go


示例16: TestFilterRender

func TestFilterRender(t *testing.T) {
	renderer := render.FilterUnconnected(
		mockRenderer{RenderableNodes: render.RenderableNodes{
			"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("bar")},
			"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("foo")},
			"baz": {ID: "baz", Node: report.MakeNode()},
		}})
	want := render.RenderableNodes{
		"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("bar")},
		"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("foo")},
	}
	have := expected.Sterilize(renderer.Render(report.MakeReport()))
	if !reflect.DeepEqual(want, have) {
		t.Errorf("want %+v, have %+v", want, have)
	}
}
开发者ID:philipz,项目名称:scope,代码行数:16,代码来源:render_test.go


示例17: TestMapAddressIdentity

func TestMapAddressIdentity(t *testing.T) {
	for _, input := range []testcase{
		{nrn(report.MakeNode()), false},
		{nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "192.168.1.1"})), true},
	} {
		testMap(t, render.MapAddressIdentity, input)
	}
}
开发者ID:philipz,项目名称:scope,代码行数:8,代码来源:mapping_test.go


示例18: TestMapContainerImageIdentity

func TestMapContainerImageIdentity(t *testing.T) {
	for _, input := range []testcase{
		{nrn(report.MakeNode()), false},
		{nrn(report.MakeNodeWith(map[string]string{docker.ImageID: "a1b2c3"})), true},
	} {
		testMap(t, render.MapContainerImageIdentity, input)
	}
}
开发者ID:philipz,项目名称:scope,代码行数:8,代码来源:mapping_test.go


示例19: TestMapProcessIdentity

func TestMapProcessIdentity(t *testing.T) {
	for _, input := range []testcase{
		{nrn(report.MakeNode()), false},
		{nrn(report.MakeNodeWith(map[string]string{process.PID: "201"})), true},
	} {
		testMap(t, render.MapProcessIdentity, input)
	}
}
开发者ID:philipz,项目名称:scope,代码行数:8,代码来源:mapping_test.go


示例20: TestMapServiceIdentity

func TestMapServiceIdentity(t *testing.T) {
	for _, input := range []testcase{
		{nrn(report.MakeNode()), false},
		{nrn(report.MakeNodeWith(map[string]string{kubernetes.ServiceID: "ping/pong", kubernetes.ServiceName: "pong"})), true},
	} {
		testMap(t, render.MapServiceIdentity, input)
	}
}
开发者ID:rnd-ua,项目名称:scope,代码行数:8,代码来源:mapping_test.go



注:本文中的github.com/weaveworks/scope/report.MakeNode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang report.MakeNodeMetadata函数代码示例发布时间:2022-05-28
下一篇:
Golang report.MakeMetric函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap