func setupHttpServer()

in agent/agent.go [372:418]


func setupHttpServer(agentConfig config.AgentConfig,
	healthStatus *healthcheck.HealthStatus,
	snapshotter *stats.Snapshotter,
	messageSources *messagesources.MessageSources) {

	if agentConfig.AgentAdminMode == config.UDS {
		// When starting a UDS HttpServer, UDS path needs to be removed first if it exists,
		// or there will be 'address already in use' error
		if err := os.Remove(agentConfig.AgentAdminUdsPath); err != nil && !os.IsNotExist(err) {
			log.Fatalf("Failed to remove Agent Admin UDS path:[%s], %v", agentConfig.AgentAdminUdsPath, err)
			messageSources.SetAgentExit()
			return
		}
	}

	limiter := rate.NewLimiter(config.TPS_LIMIT, config.BURST_TPS_LIMIT)

	envoyLoggingHandler := logging.EnvoyLoggingHandler{
		AgentConfig: agentConfig,
		Limiter:     limiter,
	}

	envoyPrometheusStatsHandler := stats.EnvoyPrometheusStatsHandler{
		AgentConfig: agentConfig,
		Limiter:     limiter,
		Snapshotter: snapshotter,
	}

	healthHandler := healthcheck.HealthStatusHandler{
		HealthStatus: healthStatus,
		Limiter:      limiter,
	}

	envoyListenerDrainHandler := listenerdraining.EnvoyListenerDrainHandler{
		AgentConfig: agentConfig,
		Limiter:     limiter,
	}

	httpHandlers := server.HandlerSpec{
		config.AGENT_STATUS_ENDPOINT_URL:         healthHandler.EnvoyStatus,
		config.AGENT_LOGGING_ENDPOINT_URL:        envoyLoggingHandler.LoggingHandler,
		config.AGENT_STATS_ENDPOINT_URL:          envoyPrometheusStatsHandler.HandleStats,
		config.AGENT_LISTENER_DRAIN_ENDPOINT_URL: envoyListenerDrainHandler.HandleDraining,
	}

	go server.StartHttpServer(agentConfig, httpHandlers, messageSources)
}