Exemple #1
0
func CreatePodList(pods []api.Pod, dsQuery *dataselect.DataSelectQuery,
	heapsterClient client.HeapsterClient) PodList {

	channels := &common.ResourceChannels{
		PodMetrics: common.GetPodListMetricsChannel(heapsterClient, pods, 1),
	}

	if err := <-channels.PodMetrics.Error; err != nil {
		log.Printf("Skipping Heapster metrics because of error: %s\n", err)
	}
	metrics := <-channels.PodMetrics.MetricsByPod

	podList := PodList{
		Pods:     make([]Pod, 0),
		ListMeta: common.ListMeta{TotalItems: len(pods)},
	}

	podCells, cumulativeMetricsPromises := dataselect.GenericDataSelectWithMetrics(toCells(pods), dsQuery,
		dataselect.NoResourceCache, &heapsterClient)
	pods = fromCells(podCells)

	for _, pod := range pods {
		podDetail := ToPod(&pod, metrics)
		podList.Pods = append(podList.Pods, podDetail)
	}

	cumulativeMetrics, err := cumulativeMetricsPromises.GetMetrics()
	podList.CumulativeMetrics = cumulativeMetrics
	if err != nil {
		podList.CumulativeMetrics = make([]metric.Metric, 0)
	}

	return podList
}
Exemple #2
0
func CreatePodList(pods []api.Pod, events []api.Event, dsQuery *dataselect.DataSelectQuery,
	heapsterClient client.HeapsterClient) PodList {

	channels := &common.ResourceChannels{
		PodMetrics: common.GetPodListMetricsChannel(heapsterClient, pods, 1),
	}

	if err := <-channels.PodMetrics.Error; err != nil {
		log.Printf("Skipping Heapster metrics because of error: %s\n", err)
	}
	metrics := <-channels.PodMetrics.MetricsByPod

	podList := PodList{
		Pods: make([]Pod, 0),
	}

	cache := &dataselect.CachedResources{Pods: pods}

	podCells, cumulativeMetricsPromises, filteredTotal := dataselect.GenericDataSelectWithFilterAndMetrics(toCells(pods), dsQuery,
		cache, &heapsterClient)
	pods = fromCells(podCells)
	podList.ListMeta = common.ListMeta{TotalItems: filteredTotal}

	for _, pod := range pods {
		warnings := event.GetPodsEventWarnings(events, []api.Pod{pod})

		podDetail := ToPod(&pod, metrics, warnings)
		podDetail.Warnings = warnings
		podList.Pods = append(podList.Pods, podDetail)

	}
	cumulativeMetrics, err := cumulativeMetricsPromises.GetMetrics()

	podList.CumulativeMetrics = cumulativeMetrics
	if err != nil {
		podList.CumulativeMetrics = make([]metric.Metric, 0)
	}

	return podList
}