// 根路由 指向 静态页面 if webRoot != "/" { rootRouter.HandleFunc(webRoot, func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, webRootWithSlash, http.StatusFound) })
// help the user out - if a request comes in for "/", redirect to our true webroot rootRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, webRootWithSlash, http.StatusFound) })
funcGraphNamespaces(business *business.Layer, o graph.Options)(code int, config interface{}) { // time how long it takes to generate this graph promtimer := internalmetrics.GetGraphGenerationTimePrometheusTimer(o.GetGraphKind(), o.TelemetryOptions.GraphType, o.InjectServiceNodes) defer promtimer.ObserveDuration()
for _, namespace := range o.Namespaces { log.Tracef("Build traffic map for namespace [%s]", namespace) //生成一个 namespaceTrafficMap namespaceTrafficMap := buildNamespaceTrafficMap(namespace.Name, o, client) namespaceInfo := graph.NewAppenderNamespaceInfo(namespace.Name) for _, a := range appenders { appenderTimer := internalmetrics.GetGraphAppenderTimePrometheusTimer(a.Name()) a.AppendGraph(namespaceTrafficMap, globalInfo, namespaceInfo) appenderTimer.ObserveDuration() } // 将 namespaceTrafficMap merge ----> trafficMap 中 telemetry.MergeTrafficMaps(trafficMap, namespace.Name, namespaceTrafficMap) }
// The appenders can add/remove/alter nodes. After the manipulations are complete // we can make some final adjustments: // - mark the outsiders (i.e. nodes not in the requested namespaces) // - mark the insider traffic generators (i.e. inside the namespace and only outgoing edges) telemetry.MarkOutsideOrInaccessible(trafficMap, o) telemetry.MarkTrafficGenerators(trafficMap)
if graph.GraphTypeService == o.GraphType { trafficMap = telemetry.ReduceToServiceGraph(trafficMap) }
return trafficMap }
Appender 这个interface 主要负责获取和组装流量视图的节点信息和线的信息
graph/appender.go
1 2 3 4 5 6 7 8 9 10 11
// Appender is implemented by any code offering to append a service graph with // supplemental information. On error the appender should panic and it will be // handled as an error response. type Appender interface { // AppendGraph performs the appender work on the provided traffic map. The map // may be initially empty. An appender is allowed to add or remove map entries. AppendGraph(trafficMap TrafficMap, globalInfo *AppenderGlobalInfo, namespaceInfo *AppenderNamespaceInfo) // Name returns a unique appender name and which is the name used to identify the appender (e.g in 'appenders' query param) Name() string }