# Update SVG with this command:
# dot architecture.dot -Tsvg -oarchitecture.svg

digraph G {
	label="Kubernetes Test Infrastructure (Last updated 2021-03-04)"  # UPDATE WHEN CHANGED!
    labelloc="t"
    graph[compound=true]

	# external services
	legend_ext, GCS, PubSub, "GitHub\nthrough\nghproxy", BigQuery [style=filled, fillcolor=gray, shape=square]

	# things that host websites
	legend_site Spyglass, Deck, "Testgrid (closed)", Gubernator, Velodrome, Boskos, Greenhouse [shape=house, fillcolor=lightblue, style=filled]

    legend_cloud GCE, GKE, AWS [shape=doubleoctagon, fillcolor=gray, style=filled]

    legend_prowjob Metrics, Triage, ProwJobs [shape=square, fillcolor=dodgerblue1, style=filled]

    legend_stock InfluxDB, Prometheus [shape=cylinder, fillcolor=gray98, style=filled]

	# handy links!
	Triage [href="https://go.k8s.io/triage"]
	Gubernator [href="https://gubernator.k8s.io"]
	"Testgrid (closed)" [href="https://testgrid.k8s.io"]
	Deck [href="https://prow.k8s.io"]
	BigQuery [href="https://bigquery.cloud.google.com/table/k8s_infra_kettle:build.week"]

	subgraph cluster_Prow {
		label="Prow"
		color=blue
		Hook [label="Hook\nhandle GitHub events"]
		Deck [label="Deck\nfrontend"]
		Plank [label="Plank\nProwJob controller"]
		Sinker [label="Sinker\ndeletes old\npods/ProwJobs"]
		Horologium [label="Horologium\ncreate periodic ProwJobs"]
		Job
		ApiServer [label="Kubernetes\nAPI Server" shape=septagon]
	}

	subgraph cluster_legend {
		label="Legend"
		rank=sink
		legend_ext [label="External\nService"]
		legend_site [label="Serves\nHTTP"]
		legend_cloud [label="Cloud\nor\nCloud service"]
        legend_prowjob [label="ProwJobs"]
        legend_stock [label="Hosted stock"]
	}

	# CONNECTIONS START HERE:
	# graphviz's dot rendering engine generally tries to lay things out
	# top to bottom, following edges. dir="back" is an orientation hint
	# to the layout engine, to try to keep hierarchy in a sensible order.
	# hack to get legend near the bottom
	"Testgrid (closed)" -> legend_ext [style="invis"]

	Kettle [label="Kettle\nget GCS results into BQ"]

	"GitHub\nthrough\nghproxy" -> Gubernator [label="PR events", dir="both"]
	"GitHub\nthrough\nghproxy" -> Hook [label="events"]
	GCS -> Gubernator [dir="back"]
	Gubernator -> "Testgrid (closed)" [dir="back"]
	Job -> GCS [label="publish\nstarted.json, finished.json,\nbuild-log.txt, artifacts/", dir="both"]

	Plank -> "GitHub\nthrough\nghproxy" [label="update PR status\ncomment failures", ltail="cluster_Prow"]

	subgraph cluster_Prow {
		Plank -> ApiServer
		Splice -> ApiServer
		Deck -> ApiServer [label="read"]
		Hook -> ApiServer [label="create ProwJob"]
		ApiServer -> Job [label="start Pod"]
		ApiServer -> Sinker [dir="back"]
		ApiServer -> Horologium [dir="back"]
	}

	GCS -> PubSub
	PubSub -> Kettle [label="read"]
	Kettle -> BigQuery [label="write"]
    BigQuery -> Triage
    BigQuery -> Metrics
	GCS -> Triage [dir="back"]
	GCS -> "Testgrid (closed)"
    GCS -> Spyglass
    Spyglass -> GKE [dir="both"]
    Metrics -> InfluxDB
    Prometheus -> InfluxDB
    InfluxDB -> Velodrome
    Plank -> Prometheus [ltail="cluster_Prow"]
    Boskos -> Prometheus
    Boskos -> ProwJobs [dir="both"]
    Boskos -> GCE [dir="both"]
    Boskos -> GKE [dir="both"]
    ProwJobs -> AWS [dir="both"]
    ProwJobs -> GKE [dir="both"]
    ProwJobs -> GCE [dir="both"]
    ProwJobs -> Greenhouse [dir="both"]
}
