本文整理汇总了Golang中github.com/weaveworks/scope/report.MakeNodeMetadataWith函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeNodeMetadataWith函数的具体用法?Golang MakeNodeMetadataWith怎么用?Golang MakeNodeMetadataWith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeNodeMetadataWith函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestTagger
func TestTagger(t *testing.T) {
oldProcessTree := docker.NewProcessTreeStub
defer func() { docker.NewProcessTreeStub = oldProcessTree }()
docker.NewProcessTreeStub = func(_ process.Walker) (process.Tree, error) {
return &mockProcessTree{map[int]int{2: 1}}, nil
}
var (
pid1NodeID = report.MakeProcessNodeID("somehost.com", "1")
pid2NodeID = report.MakeProcessNodeID("somehost.com", "2")
wantNodeMetadata = report.MakeNodeMetadataWith(map[string]string{docker.ContainerID: "ping"})
)
input := report.MakeReport()
input.Process.NodeMetadatas[pid1NodeID] = report.MakeNodeMetadataWith(map[string]string{"pid": "1"})
input.Process.NodeMetadatas[pid2NodeID] = report.MakeNodeMetadataWith(map[string]string{"pid": "2"})
want := report.MakeReport()
want.Process.NodeMetadatas[pid1NodeID] = report.MakeNodeMetadataWith(map[string]string{"pid": "1"}).Merge(wantNodeMetadata)
want.Process.NodeMetadatas[pid2NodeID] = report.MakeNodeMetadataWith(map[string]string{"pid": "2"}).Merge(wantNodeMetadata)
tagger := docker.NewTagger(mockRegistryInstance, nil)
have, err := tagger.Tag(input)
if err != nil {
t.Errorf("%v", err)
}
if !reflect.DeepEqual(want, have) {
t.Errorf("%s", test.Diff(want, have))
}
}
开发者ID:barravi,项目名称:scope,代码行数:31,代码来源:tagger_test.go
示例2: TestReporter
func TestReporter(t *testing.T) {
want := report.MakeReport()
want.Container = report.Topology{
Adjacency: report.Adjacency{},
EdgeMetadatas: report.EdgeMetadatas{},
NodeMetadatas: report.NodeMetadatas{
report.MakeContainerNodeID("", "ping"): report.MakeNodeMetadataWith(map[string]string{
docker.ContainerID: "ping",
docker.ContainerName: "pong",
docker.ImageID: "baz",
}),
},
}
want.ContainerImage = report.Topology{
Adjacency: report.Adjacency{},
EdgeMetadatas: report.EdgeMetadatas{},
NodeMetadatas: report.NodeMetadatas{
report.MakeContainerNodeID("", "baz"): report.MakeNodeMetadataWith(map[string]string{
docker.ImageID: "baz",
docker.ImageName: "bang",
}),
},
}
reporter := docker.NewReporter(mockRegistryInstance, "")
have, _ := reporter.Report()
if !reflect.DeepEqual(want, have) {
t.Errorf("%s", test.Diff(want, have))
}
}
开发者ID:barravi,项目名称:scope,代码行数:30,代码来源:reporter_test.go
示例3: TestApply
func TestApply(t *testing.T) {
var (
endpointNodeID = "c"
addressNodeID = "d"
endpointNodeMetadata = report.MakeNodeMetadataWith(map[string]string{"5": "6"})
addressNodeMetadata = report.MakeNodeMetadataWith(map[string]string{"7": "8"})
)
r := report.MakeReport()
r.Endpoint.NodeMetadatas[endpointNodeID] = endpointNodeMetadata
r.Address.NodeMetadatas[addressNodeID] = addressNodeMetadata
r = Apply(r, []Tagger{newTopologyTagger()})
for _, tuple := range []struct {
want report.NodeMetadata
from report.Topology
via string
}{
{endpointNodeMetadata.Merge(report.MakeNodeMetadataWith(map[string]string{"topology": "endpoint"})), r.Endpoint, endpointNodeID},
{addressNodeMetadata.Merge(report.MakeNodeMetadataWith(map[string]string{"topology": "address"})), r.Address, addressNodeID},
} {
if want, have := tuple.want, tuple.from.NodeMetadatas[tuple.via]; !reflect.DeepEqual(want, have) {
t.Errorf("want %+v, have %+v", want, have)
}
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:26,代码来源:tag_report_test.go
示例4: TestReporter
func TestReporter(t *testing.T) {
walker := &mockWalker{
processes: []process.Process{
{PID: 1, PPID: 0, Comm: "init"},
{PID: 2, PPID: 1, Comm: "bash"},
{PID: 3, PPID: 1, Comm: "apache", Threads: 2},
{PID: 4, PPID: 2, Comm: "ping", Cmdline: "ping foo.bar.local"},
{PID: 5, PPID: 1, Cmdline: "tail -f /var/log/syslog"},
},
}
reporter := process.NewReporter(walker, "")
want := report.MakeReport()
want.Process = report.Topology{
Adjacency: report.Adjacency{},
EdgeMetadatas: report.EdgeMetadatas{},
NodeMetadatas: report.NodeMetadatas{
report.MakeProcessNodeID("", "1"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "1",
process.Comm: "init",
process.Threads: "0",
}),
report.MakeProcessNodeID("", "2"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "2",
process.Comm: "bash",
process.PPID: "1",
process.Threads: "0",
}),
report.MakeProcessNodeID("", "3"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "3",
process.Comm: "apache",
process.PPID: "1",
process.Threads: "2",
}),
report.MakeProcessNodeID("", "4"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "4",
process.Comm: "ping",
process.PPID: "2",
process.Cmdline: "ping foo.bar.local",
process.Threads: "0",
}),
report.MakeProcessNodeID("", "5"): report.MakeNodeMetadataWith(map[string]string{
process.PID: "5",
process.PPID: "1",
process.Cmdline: "tail -f /var/log/syslog",
process.Threads: "0",
}),
},
}
have, err := reporter.Report()
if err != nil || !reflect.DeepEqual(want, have) {
t.Errorf("%s (%v)", test.Diff(want, have), err)
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:55,代码来源:reporter_test.go
示例5: TestMapEndpointIdentity
func TestMapEndpointIdentity(t *testing.T) {
for _, input := range []testcase{
{report.MakeNodeMetadata(), false},
{report.MakeNodeMetadataWith(map[string]string{endpoint.Addr: "1.2.3.4"}), false},
{report.MakeNodeMetadataWith(map[string]string{endpoint.Port: "1234"}), false},
{report.MakeNodeMetadataWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Port: "1234"}), true},
{report.MakeNodeMetadataWith(map[string]string{report.HostNodeID: report.MakeHostNodeID("foo"), endpoint.Addr: "10.0.0.1", endpoint.Port: "20001"}), true},
} {
testMap(t, render.MapEndpointIdentity, input)
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:11,代码来源:mapping_test.go
示例6: Report
// Report implements Reporter.
func (w Weave) Report() (report.Report, error) {
r := report.MakeReport()
resp, err := http.Get(w.url)
if err != nil {
log.Printf("Weave Tagger: %v", err)
return r, err
}
defer resp.Body.Close()
var status struct {
Peers []struct {
Name string `json:"Name"`
NickName string `json:"NickName"`
} `json:"Peers"`
}
if err := json.NewDecoder(resp.Body).Decode(&status); err != nil {
log.Printf("Weave Tagger: %v", err)
return r, err
}
for _, peer := range status.Peers {
r.Overlay.NodeMetadatas[report.MakeOverlayNodeID(peer.Name)] = report.MakeNodeMetadataWith(map[string]string{
WeavePeerName: peer.Name,
WeavePeerNickName: peer.NickName,
})
}
return r, nil
}
开发者ID:barravi,项目名称:scope,代码行数:30,代码来源:weave.go
示例7: Report
// Report implements Reporter.
func (r *Reporter) Report() (report.Report, error) {
var (
rep = report.MakeReport()
localCIDRs []string
)
for _, localNet := range r.localNets {
localCIDRs = append(localCIDRs, localNet.String())
}
uptime, err := GetUptime()
if err != nil {
return rep, err
}
kernel, err := GetKernelVersion()
if err != nil {
return rep, err
}
rep.Host.NodeMetadatas[report.MakeHostNodeID(r.hostID)] = report.MakeNodeMetadataWith(map[string]string{
Timestamp: Now(),
HostName: r.hostName,
LocalNetworks: strings.Join(localCIDRs, " "),
OS: runtime.GOOS,
Load: GetLoad(),
KernelVersion: kernel,
Uptime: uptime.String(),
})
return rep, nil
}
开发者ID:barravi,项目名称:scope,代码行数:33,代码来源:reporter.go
示例8: GetNodeMetadata
func (c *mockContainer) GetNodeMetadata() report.NodeMetadata {
return report.MakeNodeMetadataWith(map[string]string{
docker.ContainerID: c.c.ID,
docker.ContainerName: c.c.Name,
docker.ImageID: c.c.Image,
})
}
开发者ID:barravi,项目名称:scope,代码行数:7,代码来源:registry_test.go
示例9: TestWeaveTaggerOverlayTopology
func TestWeaveTaggerOverlayTopology(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(mockWeaveRouter))
defer s.Close()
w, err := overlay.NewWeave(s.URL)
if err != nil {
t.Fatal(err)
}
have, err := w.Report()
if err != nil {
t.Fatal(err)
}
if want, have := (report.Topology{
Adjacency: report.Adjacency{},
EdgeMetadatas: report.EdgeMetadatas{},
NodeMetadatas: report.NodeMetadatas{
report.MakeOverlayNodeID(mockWeavePeerName): report.MakeNodeMetadataWith(map[string]string{
overlay.WeavePeerName: mockWeavePeerName,
overlay.WeavePeerNickName: mockWeavePeerNickName,
}),
},
}), have.Overlay; !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
开发者ID:barravi,项目名称:scope,代码行数:26,代码来源:weave_test.go
示例10: TestMapContainerImageIdentity
func TestMapContainerImageIdentity(t *testing.T) {
for _, input := range []testcase{
{report.MakeNodeMetadata(), false},
{report.MakeNodeMetadataWith(map[string]string{docker.ImageID: "a1b2c3"}), true},
} {
testMap(t, render.MapContainerImageIdentity, input)
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:8,代码来源:mapping_test.go
示例11: TestMapAddressIdentity
func TestMapAddressIdentity(t *testing.T) {
for _, input := range []testcase{
{report.MakeNodeMetadata(), false},
{report.MakeNodeMetadataWith(map[string]string{endpoint.Addr: "192.168.1.1"}), true},
} {
testMap(t, render.MapAddressIdentity, input)
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:8,代码来源:mapping_test.go
示例12: TestMapProcessIdentity
func TestMapProcessIdentity(t *testing.T) {
for _, input := range []testcase{
{report.MakeNodeMetadata(), false},
{report.MakeNodeMetadataWith(map[string]string{process.PID: "201"}), true},
} {
testMap(t, render.MapProcessIdentity, input)
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:8,代码来源:mapping_test.go
示例13: Tag
// Tag implements Tagger.
func (t Tagger) Tag(r report.Report) (report.Report, error) {
other := report.MakeNodeMetadataWith(map[string]string{report.HostNodeID: t.hostNodeID})
for _, topology := range r.Topologies() {
for id, md := range topology.NodeMetadatas {
topology.NodeMetadatas[id] = md.Merge(other)
}
}
return r, nil
}
开发者ID:cgvarela,项目名称:scope,代码行数:10,代码来源:tagger.go
示例14: addConnection
func (r *Reporter) addConnection(rpt *report.Report, c *procspy.Connection) {
var (
localAddressNodeID = report.MakeAddressNodeID(r.hostID, c.LocalAddress.String())
remoteAddressNodeID = report.MakeAddressNodeID(r.hostID, c.RemoteAddress.String())
adjecencyID = report.MakeAdjacencyID(localAddressNodeID)
edgeID = report.MakeEdgeID(localAddressNodeID, remoteAddressNodeID)
)
rpt.Address.Adjacency[adjecencyID] = rpt.Address.Adjacency[adjecencyID].Add(remoteAddressNodeID)
if _, ok := rpt.Address.NodeMetadatas[localAddressNodeID]; !ok {
rpt.Address.NodeMetadatas[localAddressNodeID] = report.MakeNodeMetadataWith(map[string]string{
"name": r.hostName,
Addr: c.LocalAddress.String(),
})
}
countTCPConnection(rpt.Address.EdgeMetadatas, edgeID)
if c.Proc.PID > 0 {
var (
localEndpointNodeID = report.MakeEndpointNodeID(r.hostID, c.LocalAddress.String(), strconv.Itoa(int(c.LocalPort)))
remoteEndpointNodeID = report.MakeEndpointNodeID(r.hostID, c.RemoteAddress.String(), strconv.Itoa(int(c.RemotePort)))
adjecencyID = report.MakeAdjacencyID(localEndpointNodeID)
edgeID = report.MakeEdgeID(localEndpointNodeID, remoteEndpointNodeID)
)
rpt.Endpoint.Adjacency[adjecencyID] = rpt.Endpoint.Adjacency[adjecencyID].Add(remoteEndpointNodeID)
if _, ok := rpt.Endpoint.NodeMetadatas[localEndpointNodeID]; !ok {
// First hit establishes NodeMetadata for scoped local address + port
md := report.MakeNodeMetadataWith(map[string]string{
Addr: c.LocalAddress.String(),
Port: strconv.Itoa(int(c.LocalPort)),
process.PID: fmt.Sprint(c.Proc.PID),
})
rpt.Endpoint.NodeMetadatas[localEndpointNodeID] = md
}
countTCPConnection(rpt.Endpoint.EdgeMetadatas, edgeID)
}
}
开发者ID:barravi,项目名称:scope,代码行数:43,代码来源:reporter.go
示例15: GetNodeMetadata
func (c *container) GetNodeMetadata() report.NodeMetadata {
c.RLock()
defer c.RUnlock()
result := report.MakeNodeMetadataWith(map[string]string{
ContainerID: c.ID(),
ContainerName: strings.TrimPrefix(c.container.Name, "/"),
ContainerPorts: c.ports(),
ContainerCreated: c.container.Created.Format(time.RFC822),
ContainerCommand: c.container.Path + " " + strings.Join(c.container.Args, " "),
ImageID: c.container.Image,
ContainerIPs: strings.Join(append(c.container.NetworkSettings.SecondaryIPAddresses,
c.container.NetworkSettings.IPAddress), " "),
})
AddLabels(result, c.container.Config.Labels)
if c.latestStats == nil {
return result
}
result = result.Merge(report.MakeNodeMetadataWith(map[string]string{
NetworkRxDropped: strconv.FormatUint(c.latestStats.Network.RxDropped, 10),
NetworkRxBytes: strconv.FormatUint(c.latestStats.Network.RxBytes, 10),
NetworkRxErrors: strconv.FormatUint(c.latestStats.Network.RxErrors, 10),
NetworkTxPackets: strconv.FormatUint(c.latestStats.Network.TxPackets, 10),
NetworkTxDropped: strconv.FormatUint(c.latestStats.Network.TxDropped, 10),
NetworkRxPackets: strconv.FormatUint(c.latestStats.Network.RxPackets, 10),
NetworkTxErrors: strconv.FormatUint(c.latestStats.Network.TxErrors, 10),
NetworkTxBytes: strconv.FormatUint(c.latestStats.Network.TxBytes, 10),
MemoryMaxUsage: strconv.FormatUint(c.latestStats.MemoryStats.MaxUsage, 10),
MemoryUsage: strconv.FormatUint(c.latestStats.MemoryStats.Usage, 10),
MemoryFailcnt: strconv.FormatUint(c.latestStats.MemoryStats.Failcnt, 10),
MemoryLimit: strconv.FormatUint(c.latestStats.MemoryStats.Limit, 10),
// CPUPercpuUsage: strconv.FormatUint(stats.CPUStats.CPUUsage.PercpuUsage, 10),
CPUUsageInUsermode: strconv.FormatUint(c.latestStats.CPUStats.CPUUsage.UsageInUsermode, 10),
CPUTotalUsage: strconv.FormatUint(c.latestStats.CPUStats.CPUUsage.TotalUsage, 10),
CPUUsageInKernelmode: strconv.FormatUint(c.latestStats.CPUStats.CPUUsage.UsageInKernelmode, 10),
CPUSystemCPUUsage: strconv.FormatUint(c.latestStats.CPUStats.SystemCPUUsage, 10),
}))
return result
}
开发者ID:cgvarela,项目名称:scope,代码行数:43,代码来源:container.go
示例16: TestMapEdge
func TestMapEdge(t *testing.T) {
selector := func(_ report.Report) report.Topology {
return report.Topology{
NodeMetadatas: report.NodeMetadatas{
"foo": report.MakeNodeMetadataWith(map[string]string{"id": "foo"}),
"bar": report.MakeNodeMetadataWith(map[string]string{"id": "bar"}),
},
Adjacency: report.Adjacency{
">foo": report.MakeIDList("bar"),
">bar": report.MakeIDList("foo"),
},
EdgeMetadatas: report.EdgeMetadatas{
"foo|bar": report.EdgeMetadata{EgressPacketCount: newu64(1), EgressByteCount: newu64(2)},
"bar|foo": report.EdgeMetadata{EgressPacketCount: newu64(3), EgressByteCount: newu64(4)},
},
}
}
identity := func(nmd report.NodeMetadata) render.RenderableNodes {
return render.RenderableNodes{nmd.Metadata["id"]: render.NewRenderableNode(nmd.Metadata["id"], "", "", "", nmd)}
}
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode) render.RenderableNodes {
id := "_" + nodes.ID
return render.RenderableNodes{id: render.RenderableNode{ID: id}}
},
Renderer: render.LeafMap{
Selector: selector,
Mapper: identity,
Pseudo: nil,
},
}
if want, have := (report.EdgeMetadata{
EgressPacketCount: newu64(1),
EgressByteCount: newu64(2),
}), mapper.EdgeMetadata(report.MakeReport(), "_foo", "_bar"); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:41,代码来源:render_test.go
示例17: Report
// Report implements Reporter.
func (w Weave) Report() (report.Report, error) {
r := report.MakeReport()
status, err := w.update()
if err != nil {
return r, err
}
for _, peer := range status.Router.Peers {
r.Overlay.NodeMetadatas[report.MakeOverlayNodeID(peer.Name)] = report.MakeNodeMetadataWith(map[string]string{
WeavePeerName: peer.Name,
WeavePeerNickName: peer.NickName,
})
}
return r, nil
}
开发者ID:cgvarela,项目名称:scope,代码行数:16,代码来源:weave.go
示例18: TestReportLocalNetworks
func TestReportLocalNetworks(t *testing.T) {
r := report.MakeReport()
r.Merge(report.Report{Host: report.Topology{NodeMetadatas: report.NodeMetadatas{
"nonets": report.MakeNodeMetadata(),
"foo": report.MakeNodeMetadataWith(map[string]string{host.LocalNetworks: "10.0.0.1/8 192.168.1.1/24 10.0.0.1/8 badnet/33"}),
}}})
want := report.Networks([]*net.IPNet{
mustParseCIDR("10.0.0.1/8"),
mustParseCIDR("192.168.1.1/24"),
})
have := render.LocalNetworks(r)
if !reflect.DeepEqual(want, have) {
t.Errorf("%s", test.Diff(want, have))
}
}
开发者ID:barravi,项目名称:scope,代码行数:15,代码来源:theinternet_test.go
示例19: Tag
// Tag implements Tagger
func (topologyTagger) Tag(r report.Report) (report.Report, error) {
for val, topology := range map[string]*report.Topology{
"endpoint": &(r.Endpoint),
"address": &(r.Address),
"process": &(r.Process),
"container": &(r.Container),
"container_image": &(r.ContainerImage),
"host": &(r.Host),
"overlay": &(r.Overlay),
} {
other := report.MakeNodeMetadataWith(map[string]string{Topology: val})
for id, md := range topology.NodeMetadatas {
topology.NodeMetadatas[id] = md.Merge(other)
}
}
return r, nil
}
开发者ID:cgvarela,项目名称:scope,代码行数:18,代码来源:tag_report.go
示例20: processTopology
func (r *Reporter) processTopology() (report.Topology, error) {
t := report.NewTopology()
err := r.walker.Walk(func(p Process) {
pidstr := strconv.Itoa(p.PID)
nodeID := report.MakeProcessNodeID(r.scope, pidstr)
t.NodeMetadatas[nodeID] = report.MakeNodeMetadataWith(map[string]string{
PID: pidstr,
Comm: p.Comm,
Cmdline: p.Cmdline,
Threads: strconv.Itoa(p.Threads),
})
if p.PPID > 0 {
t.NodeMetadatas[nodeID].Metadata[PPID] = strconv.Itoa(p.PPID)
}
})
return t, err
}
开发者ID:barravi,项目名称:scope,代码行数:18,代码来源:reporter.go
注:本文中的github.com/weaveworks/scope/report.MakeNodeMetadataWith函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论