コード例 #1
0
ファイル: metrics_util.go プロジェクト: alex-mohr/kubernetes
func (m *MetricsForE2E) PrintHumanReadable() string {
	buf := bytes.Buffer{}
	for _, interestingMetric := range InterestingApiServerMetrics {
		buf.WriteString(fmt.Sprintf("For %v:\n", interestingMetric))
		for _, sample := range (*m).ApiServerMetrics[interestingMetric] {
			buf.WriteString(fmt.Sprintf("\t%v\n", metrics.PrintSample(sample)))
		}
	}
	for _, interestingMetric := range InterestingControllerManagerMetrics {
		buf.WriteString(fmt.Sprintf("For %v:\n", interestingMetric))
		for _, sample := range (*m).ControllerManagerMetrics[interestingMetric] {
			buf.WriteString(fmt.Sprintf("\t%v\n", metrics.PrintSample(sample)))
		}
	}
	for kubelet, grabbed := range (*m).KubeletMetrics {
		buf.WriteString(fmt.Sprintf("For %v:\n", kubelet))
		for _, interestingMetric := range InterestingKubeletMetrics {
			buf.WriteString(fmt.Sprintf("\tFor %v:\n", interestingMetric))
			for _, sample := range grabbed[interestingMetric] {
				buf.WriteString(fmt.Sprintf("\t\t%v\n", metrics.PrintSample(sample)))
			}
		}
	}
	return buf.String()
}
コード例 #2
0
ファイル: framework.go プロジェクト: houcy/kubernetes
// afterEach deletes the namespace, after reading its events.
func (f *Framework) afterEach() {
	// Print events if the test failed.
	if CurrentGinkgoTestDescription().Failed {
		By(fmt.Sprintf("Collecting events from namespace %q.", f.Namespace.Name))
		events, err := f.Client.Events(f.Namespace.Name).List(api.ListOptions{})
		Expect(err).NotTo(HaveOccurred())

		for _, e := range events.Items {
			Logf("event for %v: %v %v: %v", e.InvolvedObject.Name, e.Source, e.Reason, e.Message)
		}
		// Note that we don't wait for any cleanup to propagate, which means
		// that if you delete a bunch of pods right before ending your test,
		// you may or may not see the killing/deletion/cleanup events.

		dumpAllPodInfo(f.Client)

		dumpAllNodeInfo(f.Client)
	}

	// Check whether all nodes are ready after the test.
	if err := allNodesReady(f.Client, time.Minute); err != nil {
		Failf("All nodes should be ready after test, %v", err)
	}

	if testContext.DeleteNamespace {
		By(fmt.Sprintf("Destroying namespace %q for this suite.", f.Namespace.Name))

		timeout := 5 * time.Minute
		if f.NamespaceDeletionTimeout != 0 {
			timeout = f.NamespaceDeletionTimeout
		}
		if err := deleteNS(f.Client, f.Namespace.Name, timeout); err != nil {
			Failf("Couldn't delete ns %q: %s", f.Namespace.Name, err)
		}
	} else {
		Logf("Found DeleteNamespace=false, skipping namespace deletion!")
	}

	summaries := make([]TestDataSummary, 0)
	if testContext.GatherKubeSystemResourceUsageData {
		summaries = append(summaries, f.gatherer.stopAndSummarize([]int{50, 90, 99, 100}, f.addonResourceConstraints))
	}

	if testContext.GatherLogsSizes {
		close(f.logsSizeCloseChannel)
		f.logsSizeWaitGroup.Wait()
		summaries = append(summaries, f.logsSizeVerifier.GetSummary())
	}

	outputTypes := strings.Split(testContext.OutputPrintType, ",")
	for _, printType := range outputTypes {
		switch printType {
		case "hr":
			for i := range summaries {
				Logf(summaries[i].PrintHumanReadable())
			}
		case "json":
			for i := range summaries {
				Logf(summaries[i].PrintJSON())
			}
		default:
			Logf("Unknown ouptut type: %v. Skipping.", printType)
		}
	}

	if testContext.GatherMetricsAfterTest {
		// TODO: enable Scheduler and ControllerManager metrics grabbing when Master's Kubelet will be registered.
		grabber, err := metrics.NewMetricsGrabber(f.Client, true, false, false, true)
		if err != nil {
			Logf("Failed to create MetricsGrabber. Skipping metrics gathering.")
		} else {
			received, err := grabber.Grab(nil)
			if err != nil {
				Logf("MetricsGrabber failed grab metrics. Skipping metrics gathering.")
			} else {
				buf := bytes.Buffer{}
				for interestingMetric := range InterestingApiServerMetrics {
					buf.WriteString(fmt.Sprintf("For %v:\n", interestingMetric))
					for _, sample := range received.ApiServerMetrics[interestingMetric] {
						buf.WriteString(fmt.Sprintf("\t%v\n", metrics.PrintSample(sample)))
					}
				}
				for kubelet, grabbed := range received.KubeletMetrics {
					buf.WriteString(fmt.Sprintf("For %v:\n", kubelet))
					for interestingMetric := range InterestingKubeletMetrics {
						buf.WriteString(fmt.Sprintf("\tFor %v:\n", interestingMetric))
						for _, sample := range grabbed[interestingMetric] {
							buf.WriteString(fmt.Sprintf("\t\t%v\n", metrics.PrintSample(sample)))
						}
					}
				}
				Logf("%v", buf.String())
			}
		}
	}

	// Paranoia-- prevent reuse!
	f.Namespace = nil
	f.Client = nil
}