expected.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. package expected
  2. import (
  3. "github.com/weaveworks/scope/probe/docker"
  4. "github.com/weaveworks/scope/probe/kubernetes"
  5. "github.com/weaveworks/scope/probe/process"
  6. "github.com/weaveworks/scope/render"
  7. "github.com/weaveworks/scope/report"
  8. "github.com/weaveworks/scope/test/fixture"
  9. )
  10. // Exported for testing.
  11. var (
  12. circle = "circle"
  13. square = "square"
  14. heptagon = "heptagon"
  15. hexagon = "hexagon"
  16. cloud = "cloud"
  17. cylinder = "cylinder"
  18. dottedcylinder = "dottedcylinder"
  19. storagesheet = "sheet"
  20. // Helper to make a report.node with some common options
  21. node = func(topology string) func(id string, adjacent ...string) report.Node {
  22. return func(id string, adjacent ...string) report.Node {
  23. n := report.MakeNode(id).WithTopology(topology)
  24. for _, a := range adjacent {
  25. n = n.WithAdjacent(a)
  26. }
  27. return n
  28. }
  29. }
  30. pseudo = node(render.Pseudo)
  31. endpoint = node(report.Endpoint)
  32. processNode = node(report.Process)
  33. processNameNode = node(render.MakeGroupNodeTopology(report.Process, process.Name))
  34. container = node(report.Container)
  35. containerHostnameNode = node(render.MakeGroupNodeTopology(report.Container, docker.ContainerHostname))
  36. containerImage = node(report.ContainerImage)
  37. pod = node(report.Pod)
  38. service = node(report.Service)
  39. hostNode = node(report.Host)
  40. persistentVolume = node(report.PersistentVolume)
  41. persistentVolumeClaim = node(report.PersistentVolumeClaim)
  42. StorageClass = node(report.StorageClass)
  43. volumeSnapshot = node(report.VolumeSnapshot)
  44. volumeSnapshotData = node(report.VolumeSnapshotData)
  45. UnknownPseudoNode1ID = render.MakePseudoNodeID(fixture.UnknownClient1IP)
  46. UnknownPseudoNode2ID = render.MakePseudoNodeID(fixture.UnknownClient3IP)
  47. unknownPseudoNode1 = func(adjacent ...string) report.Node {
  48. return pseudo(UnknownPseudoNode1ID, adjacent...).
  49. WithChildren(report.MakeNodeSet(
  50. RenderedEndpoints[fixture.UnknownClient1NodeID],
  51. RenderedEndpoints[fixture.UnknownClient2NodeID],
  52. ))
  53. }
  54. unknownPseudoNode2 = func(adjacent ...string) report.Node {
  55. return pseudo(UnknownPseudoNode2ID, adjacent...).
  56. WithChildren(report.MakeNodeSet(
  57. RenderedEndpoints[fixture.UnknownClient3NodeID],
  58. ))
  59. }
  60. theIncomingInternetNode = func(adjacent ...string) report.Node {
  61. return pseudo(render.IncomingInternetID, adjacent...).
  62. WithChildren(report.MakeNodeSet(
  63. RenderedEndpoints[fixture.RandomClientNodeID],
  64. ))
  65. }
  66. theOutgoingInternetNode = pseudo(render.OutgoingInternetID).WithChildren(report.MakeNodeSet(
  67. RenderedEndpoints[fixture.GoogleEndpointNodeID],
  68. ))
  69. RenderedEndpoints = report.Nodes{
  70. fixture.Client54001NodeID: endpoint(fixture.Client54001NodeID, fixture.Server80NodeID),
  71. fixture.Client54002NodeID: endpoint(fixture.Client54002NodeID, fixture.Server80NodeID),
  72. fixture.Server80NodeID: endpoint(fixture.Server80NodeID),
  73. fixture.UnknownClient1NodeID: endpoint(fixture.UnknownClient1NodeID, fixture.Server80NodeID),
  74. fixture.UnknownClient2NodeID: endpoint(fixture.UnknownClient2NodeID, fixture.Server80NodeID),
  75. fixture.UnknownClient3NodeID: endpoint(fixture.UnknownClient3NodeID, fixture.Server80NodeID),
  76. fixture.RandomClientNodeID: endpoint(fixture.RandomClientNodeID, fixture.Server80NodeID),
  77. fixture.NonContainerNodeID: endpoint(fixture.NonContainerNodeID, fixture.GoogleEndpointNodeID),
  78. fixture.GoogleEndpointNodeID: endpoint(fixture.GoogleEndpointNodeID),
  79. }
  80. RenderedProcesses = report.Nodes{
  81. fixture.ClientProcess1NodeID: processNode(fixture.ClientProcess1NodeID, fixture.ServerProcessNodeID).
  82. WithLatests(map[string]string{
  83. report.HostNodeID: fixture.ClientHostNodeID,
  84. process.PID: fixture.Client1PID,
  85. process.Name: fixture.Client1Name,
  86. }).
  87. WithChildren(report.MakeNodeSet(
  88. RenderedEndpoints[fixture.Client54001NodeID],
  89. )),
  90. fixture.ClientProcess2NodeID: processNode(fixture.ClientProcess2NodeID, fixture.ServerProcessNodeID).
  91. WithChildren(report.MakeNodeSet(
  92. RenderedEndpoints[fixture.Client54002NodeID],
  93. )),
  94. fixture.ServerProcessNodeID: processNode(fixture.ServerProcessNodeID).
  95. WithChildren(report.MakeNodeSet(
  96. RenderedEndpoints[fixture.Server80NodeID],
  97. )),
  98. fixture.NonContainerProcessNodeID: processNode(fixture.NonContainerProcessNodeID, render.OutgoingInternetID).
  99. WithChildren(report.MakeNodeSet(
  100. RenderedEndpoints[fixture.NonContainerNodeID],
  101. )),
  102. // due to https://github.com/weaveworks/scope/issues/1323 we are dropping
  103. // all non-internet pseudo nodes for now.
  104. // UnknownPseudoNode1ID: unknownPseudoNode1(fixture.ServerProcessNodeID),
  105. // UnknownPseudoNode2ID: unknownPseudoNode2(fixture.ServerProcessNodeID),
  106. render.IncomingInternetID: theIncomingInternetNode(fixture.ServerProcessNodeID),
  107. render.OutgoingInternetID: theOutgoingInternetNode,
  108. }
  109. RenderedProcessNames = report.Nodes{
  110. fixture.Client1Name: processNameNode(fixture.Client1Name, fixture.ServerName).
  111. WithLatests(map[string]string{process.Name: fixture.Client1Name}).
  112. AddCounter(report.Process, 2).
  113. WithChildren(report.MakeNodeSet(
  114. RenderedEndpoints[fixture.Client54001NodeID],
  115. RenderedEndpoints[fixture.Client54002NodeID],
  116. RenderedProcesses[fixture.ClientProcess1NodeID],
  117. RenderedProcesses[fixture.ClientProcess2NodeID],
  118. )),
  119. fixture.ServerName: processNameNode(fixture.ServerName).
  120. WithLatests(map[string]string{process.Name: fixture.ServerName}).
  121. AddCounter(report.Process, 1).
  122. WithChildren(report.MakeNodeSet(
  123. RenderedEndpoints[fixture.Server80NodeID],
  124. RenderedProcesses[fixture.ServerProcessNodeID],
  125. )),
  126. fixture.NonContainerName: processNameNode(fixture.NonContainerName, render.OutgoingInternetID).
  127. AddCounter(report.Process, 1).
  128. WithChildren(report.MakeNodeSet(
  129. RenderedEndpoints[fixture.NonContainerNodeID],
  130. RenderedProcesses[fixture.NonContainerProcessNodeID],
  131. )),
  132. // due to https://github.com/weaveworks/scope/issues/1323 we are dropping
  133. // all non-internet pseudo nodes for now.
  134. // UnknownPseudoNode1ID: unknownPseudoNode1(fixture.ServerName),
  135. // UnknownPseudoNode2ID: unknownPseudoNode2(fixture.ServerName),
  136. render.IncomingInternetID: theIncomingInternetNode(fixture.ServerName),
  137. render.OutgoingInternetID: theOutgoingInternetNode,
  138. }
  139. uncontainedServerID = render.MakePseudoNodeID(render.UncontainedID, fixture.ServerHostID)
  140. uncontainedServerNode = pseudo(uncontainedServerID, render.OutgoingInternetID).WithChildren(report.MakeNodeSet(
  141. RenderedEndpoints[fixture.NonContainerNodeID],
  142. RenderedProcesses[fixture.NonContainerProcessNodeID],
  143. ))
  144. RenderedContainers = report.Nodes{
  145. fixture.ClientContainerNodeID: container(fixture.ClientContainerNodeID, fixture.ServerContainerNodeID).
  146. WithLatests(map[string]string{
  147. report.HostNodeID: fixture.ClientHostNodeID,
  148. docker.ContainerID: fixture.ClientContainerID,
  149. docker.ContainerName: fixture.ClientContainerName,
  150. docker.ImageName: fixture.ClientContainerImageName,
  151. }).
  152. WithChildren(report.MakeNodeSet(
  153. RenderedEndpoints[fixture.Client54001NodeID],
  154. RenderedEndpoints[fixture.Client54002NodeID],
  155. RenderedProcesses[fixture.ClientProcess1NodeID],
  156. RenderedProcesses[fixture.ClientProcess2NodeID],
  157. )),
  158. fixture.ServerContainerNodeID: container(fixture.ServerContainerNodeID).
  159. WithChildren(report.MakeNodeSet(
  160. RenderedEndpoints[fixture.Server80NodeID],
  161. RenderedProcesses[fixture.ServerProcessNodeID],
  162. )),
  163. fixture.ServerContainer2NodeID: container(fixture.ServerContainer2NodeID),
  164. uncontainedServerID: uncontainedServerNode,
  165. render.IncomingInternetID: theIncomingInternetNode(fixture.ServerContainerNodeID),
  166. render.OutgoingInternetID: theOutgoingInternetNode,
  167. }
  168. RenderedContainerHostnames = report.Nodes{
  169. fixture.ClientContainerHostname: containerHostnameNode(fixture.ClientContainerHostname, fixture.ServerContainerHostname).
  170. WithLatests(map[string]string{
  171. docker.ContainerHostname: fixture.ClientContainerHostname,
  172. }).
  173. AddCounter(report.Container, 1).
  174. WithChildren(report.MakeNodeSet(
  175. RenderedEndpoints[fixture.Client54001NodeID],
  176. RenderedEndpoints[fixture.Client54002NodeID],
  177. RenderedProcesses[fixture.ClientProcess1NodeID],
  178. RenderedProcesses[fixture.ClientProcess2NodeID],
  179. RenderedContainers[fixture.ClientContainerNodeID],
  180. )),
  181. fixture.ServerContainerHostname: containerHostnameNode(fixture.ServerContainerHostname).
  182. WithLatests(map[string]string{
  183. docker.ContainerHostname: fixture.ServerContainerHostname,
  184. }).
  185. AddCounter(report.Container, 2).
  186. WithChildren(report.MakeNodeSet(
  187. RenderedEndpoints[fixture.Server80NodeID],
  188. RenderedProcesses[fixture.ServerProcessNodeID],
  189. RenderedContainers[fixture.ServerContainerNodeID],
  190. RenderedContainers[fixture.ServerContainer2NodeID],
  191. )),
  192. uncontainedServerID: uncontainedServerNode,
  193. render.IncomingInternetID: theIncomingInternetNode(fixture.ServerContainerHostname),
  194. render.OutgoingInternetID: theOutgoingInternetNode,
  195. }
  196. ClientContainerImageNodeID = report.MakeContainerImageNodeID(fixture.ClientContainerImageName)
  197. ServerContainerImageNodeID = report.MakeContainerImageNodeID(fixture.ServerContainerImageName)
  198. RenderedContainerImages = report.Nodes{
  199. ClientContainerImageNodeID: containerImage(ClientContainerImageNodeID, ServerContainerImageNodeID).
  200. WithLatests(map[string]string{
  201. report.HostNodeID: fixture.ClientHostNodeID,
  202. docker.ImageID: fixture.ClientContainerImageID,
  203. docker.ImageName: fixture.ClientContainerImageName,
  204. }).
  205. AddCounter(report.Container, 1).
  206. WithChildren(report.MakeNodeSet(
  207. RenderedEndpoints[fixture.Client54001NodeID],
  208. RenderedEndpoints[fixture.Client54002NodeID],
  209. RenderedProcesses[fixture.ClientProcess1NodeID],
  210. RenderedProcesses[fixture.ClientProcess2NodeID],
  211. RenderedContainers[fixture.ClientContainerNodeID],
  212. )),
  213. ServerContainerImageNodeID: containerImage(ServerContainerImageNodeID).
  214. AddCounter(report.Container, 2).
  215. WithChildren(report.MakeNodeSet(
  216. RenderedEndpoints[fixture.Server80NodeID],
  217. RenderedProcesses[fixture.ServerProcessNodeID],
  218. RenderedContainers[fixture.ServerContainerNodeID],
  219. RenderedContainers[fixture.ServerContainer2NodeID],
  220. )),
  221. uncontainedServerID: uncontainedServerNode,
  222. render.IncomingInternetID: theIncomingInternetNode(ServerContainerImageNodeID),
  223. render.OutgoingInternetID: theOutgoingInternetNode,
  224. }
  225. UnmanagedServerID = render.MakePseudoNodeID(render.UnmanagedID, fixture.ServerHostID)
  226. unmanagedServerNode = pseudo(UnmanagedServerID, render.OutgoingInternetID).WithChildren(report.MakeNodeSet(
  227. uncontainedServerNode,
  228. RenderedEndpoints[fixture.NonContainerNodeID],
  229. RenderedProcesses[fixture.NonContainerProcessNodeID],
  230. RenderedContainers[fixture.ServerContainer2NodeID],
  231. )).
  232. AddCounter(report.Container, 1).
  233. AddCounter(render.Pseudo, 1)
  234. RenderedPods = report.Nodes{
  235. fixture.ClientPodNodeID: pod(fixture.ClientPodNodeID, fixture.ServerPodNodeID).
  236. AddCounter(report.Container, 1).
  237. WithChildren(report.MakeNodeSet(
  238. RenderedEndpoints[fixture.Client54001NodeID],
  239. RenderedEndpoints[fixture.Client54002NodeID],
  240. RenderedProcesses[fixture.ClientProcess1NodeID],
  241. RenderedProcesses[fixture.ClientProcess2NodeID],
  242. RenderedContainers[fixture.ClientContainerNodeID],
  243. )),
  244. fixture.ServerPodNodeID: pod(fixture.ServerPodNodeID).
  245. AddCounter(report.Container, 1).
  246. WithChildren(report.MakeNodeSet(
  247. RenderedEndpoints[fixture.Server80NodeID],
  248. RenderedProcesses[fixture.ServerProcessNodeID],
  249. RenderedContainers[fixture.ServerContainerNodeID],
  250. )),
  251. fixture.PersistentVolumeClaimNodeID: persistentVolumeClaim(fixture.PersistentVolumeClaimNodeID, fixture.PersistentVolumeNodeID).
  252. WithLatests(map[string]string{
  253. kubernetes.Name: "pvc-6124",
  254. kubernetes.Namespace: "ping",
  255. kubernetes.Status: "bound",
  256. kubernetes.VolumeName: "pongvolume",
  257. kubernetes.AccessModes: "ReadWriteOnce",
  258. kubernetes.StorageClassName: "standard",
  259. }).WithChild(report.MakeNode(fixture.PersistentVolumeNodeID).WithTopology(report.PersistentVolume)),
  260. fixture.PersistentVolumeNodeID: persistentVolume(fixture.PersistentVolumeNodeID, fixture.VolumeSnapshotNodeID).
  261. WithLatests(map[string]string{
  262. kubernetes.Name: "pongvolume",
  263. kubernetes.Namespace: "ping",
  264. kubernetes.Status: "bound",
  265. kubernetes.VolumeClaim: "pvc-6124",
  266. kubernetes.AccessModes: "ReadWriteOnce",
  267. kubernetes.StorageClassName: "standard",
  268. kubernetes.StorageDriver: "iSCSI",
  269. }).WithChild(report.MakeNode(fixture.VolumeSnapshotNodeID).WithTopology(report.VolumeSnapshot)),
  270. fixture.StorageClassNodeID: StorageClass(fixture.StorageClassNodeID, fixture.PersistentVolumeClaimNodeID).
  271. WithLatests(map[string]string{
  272. kubernetes.Name: "standard",
  273. kubernetes.Provisioner: "pong",
  274. }).WithChild(report.MakeNode(fixture.PersistentVolumeClaimNodeID).WithTopology(report.PersistentVolumeClaim)),
  275. fixture.VolumeSnapshotNodeID: volumeSnapshot(fixture.VolumeSnapshotNodeID, fixture.VolumeSnapshotDataNodeID).
  276. WithLatests(map[string]string{
  277. kubernetes.Name: "vs-1234",
  278. kubernetes.Namespace: "ping",
  279. kubernetes.VolumeClaim: "pvc-6124",
  280. kubernetes.SnapshotData: "vsd-1234",
  281. kubernetes.VolumeName: "pongvolume",
  282. }).WithChild(report.MakeNode(fixture.VolumeSnapshotDataNodeID).WithTopology(report.VolumeSnapshotData)),
  283. fixture.VolumeSnapshotDataNodeID: volumeSnapshotData(fixture.VolumeSnapshotDataNodeID).
  284. WithLatests(map[string]string{
  285. kubernetes.Name: "vsd-1234",
  286. kubernetes.VolumeName: "pongvolume",
  287. kubernetes.VolumeSnapshotName: "vs-1234",
  288. }),
  289. UnmanagedServerID: unmanagedServerNode,
  290. render.IncomingInternetID: theIncomingInternetNode(fixture.ServerPodNodeID),
  291. render.OutgoingInternetID: theOutgoingInternetNode,
  292. }
  293. RenderedPodServices = report.Nodes{
  294. fixture.ServiceNodeID: service(fixture.ServiceNodeID, fixture.ServiceNodeID).
  295. AddCounter(report.Pod, 2).
  296. WithChildren(report.MakeNodeSet(
  297. RenderedEndpoints[fixture.Client54001NodeID],
  298. RenderedEndpoints[fixture.Client54002NodeID],
  299. RenderedEndpoints[fixture.Server80NodeID],
  300. RenderedProcesses[fixture.ClientProcess1NodeID],
  301. RenderedProcesses[fixture.ClientProcess2NodeID],
  302. RenderedProcesses[fixture.ServerProcessNodeID],
  303. RenderedContainers[fixture.ClientContainerNodeID],
  304. RenderedContainers[fixture.ServerContainerNodeID],
  305. RenderedPods[fixture.ClientPodNodeID],
  306. RenderedPods[fixture.ServerPodNodeID],
  307. )),
  308. UnmanagedServerID: unmanagedServerNode,
  309. render.IncomingInternetID: theIncomingInternetNode(fixture.ServiceNodeID),
  310. render.OutgoingInternetID: theOutgoingInternetNode,
  311. }
  312. RenderedHosts = report.Nodes{
  313. fixture.ClientHostNodeID: hostNode(fixture.ClientHostNodeID, fixture.ServerHostNodeID).
  314. WithLatests(map[string]string{
  315. report.HostName: fixture.ClientHostName,
  316. }).
  317. AddCounter(report.Container, 1).
  318. AddCounter(report.ContainerImage, 1).
  319. AddCounter(report.Pod, 1).
  320. AddCounter(report.Process, 2).
  321. WithChildren(report.MakeNodeSet(
  322. RenderedEndpoints[fixture.Client54001NodeID],
  323. RenderedEndpoints[fixture.Client54002NodeID],
  324. RenderedProcesses[fixture.ClientProcess1NodeID],
  325. RenderedProcesses[fixture.ClientProcess2NodeID],
  326. RenderedContainers[fixture.ClientContainerNodeID],
  327. RenderedContainerImages[ClientContainerImageNodeID],
  328. RenderedPods[fixture.ClientPodNodeID],
  329. )),
  330. fixture.ServerHostNodeID: hostNode(fixture.ServerHostNodeID, render.OutgoingInternetID).
  331. AddCounter(report.Container, 2).
  332. AddCounter(report.ContainerImage, 1).
  333. AddCounter(report.Pod, 1).
  334. AddCounter(report.Process, 2).
  335. WithChildren(report.MakeNodeSet(
  336. RenderedEndpoints[fixture.Server80NodeID],
  337. RenderedEndpoints[fixture.NonContainerNodeID],
  338. RenderedProcesses[fixture.ServerProcessNodeID],
  339. RenderedProcesses[fixture.NonContainerProcessNodeID],
  340. RenderedContainers[fixture.ServerContainerNodeID],
  341. RenderedContainers[fixture.ServerContainer2NodeID],
  342. RenderedContainerImages[ServerContainerImageNodeID],
  343. RenderedPods[fixture.ServerPodNodeID],
  344. )),
  345. // due to https://github.com/weaveworks/scope/issues/1323 we are dropping
  346. // all non-internet pseudo nodes for now.
  347. // UnknownPseudoNode1ID: unknownPseudoNode1(fixture.ServerHostNodeID),
  348. // UnknownPseudoNode2ID: unknownPseudoNode2(fixture.ServerHostNodeID),
  349. render.IncomingInternetID: theIncomingInternetNode(fixture.ServerHostNodeID),
  350. render.OutgoingInternetID: theOutgoingInternetNode,
  351. }
  352. )
  353. func newu64(value uint64) *uint64 { return &value }