示例#1
0
func getLatencyData(client *jenkins.JenkinsClient, job string) (TestToBuildData, sets.String, sets.String, error) {
	buildLatency := TestToBuildData{}
	resources := sets.NewString()
	methods := sets.NewString()

	queue, err := client.GetJob(job)
	if err != nil {
		return buildLatency, resources, methods, err
	}

	for ix := range queue.Builds {
		build := queue.Builds[ix]
		if build.Number < *startFrom {
			continue
		}
		reader, err := client.GetConsoleLog(job, build.Number)
		if err != nil {
			fmt.Printf("error getting logs: %v\n", err)
			continue
		}
		defer reader.Close()
		scanner := bufio.NewScanner(reader)
		hist := parseTestOutput(scanner, build.Number, resources, methods)

		for k, v := range hist {
			if _, ok := buildLatency[k]; !ok {
				buildLatency[k] = make(BuildLatencyData)
			}
			buildLatency[k][fmt.Sprintf("%d", build.Number)] = v
		}
	}
	return buildLatency, resources, methods, nil
}
示例#2
0
func getLatencyData(client *jenkins.JenkinsClient, job string) (BuildLatencyData, sets.String, sets.String, error) {
	buildLatency := BuildLatencyData{}
	resources := sets.NewString()
	methods := sets.NewString()

	queue, err := client.GetJob(job)
	if err != nil {
		return buildLatency, resources, methods, err
	}

	for ix := range queue.Builds {
		build := queue.Builds[ix]
		reader, err := client.GetConsoleLog(job, build.Number)
		if err != nil {
			fmt.Printf("error getting logs: %v", err)
			continue
		}
		defer reader.Close()
		scanner := bufio.NewScanner(reader)
		buff := &bytes.Buffer{}
		inLatency := false

		hist := ResourceToHistogram{}
		found := false
		testNameSeparator := "[It] [Feature:Performance]"
		testName := ""
		for scanner.Scan() {
			line := scanner.Text()
			if strings.Contains(line, testNameSeparator) {
				testName = strings.Trim(strings.Split(line, testNameSeparator)[1], " ")
			}
			// TODO: This is brittle, we should emit a tail delimiter too
			if strings.Contains(line, "INFO") || strings.Contains(line, "STEP") || strings.Contains(line, "Failure") {
				if inLatency {
					obj := LatencyData{}
					if err := json.Unmarshal(buff.Bytes(), &obj); err != nil {
						fmt.Printf("error parsing JSON in build %d: %v %s\n", build.Number, err, buff.String())
						// reset state and try again with more input
						inLatency = false
						continue
					}

					if testName == "should allow starting 30 pods per node" {
						for _, call := range obj.APICalls {
							list := hist[call.Resource]
							list = append(list, call)
							hist[call.Resource] = list
							resources.Insert(call.Resource)
							methods.Insert(call.Verb)
						}
					}

					buff.Reset()
				}
				inLatency = false
			}
			if strings.Contains(line, "API calls latencies") {
				found = true
				inLatency = true
				ix = strings.Index(line, "{")
				line = line[ix:]
			}
			if inLatency {
				buff.WriteString(line + " ")
			}
		}
		if !found {
			continue
		}

		buildLatency[fmt.Sprintf("%d", build.Number)] = hist
	}
	return buildLatency, resources, methods, nil
}