Пример #1
0
func Dump(prefix string, output io.Writer) int {
	log.INFO.Println("Reading measures stored in git")
	gitlog := store.CommitMeasureCommand(prefix)

	readStoredMeasure, err := store.CommitMeasures(gitlog)
	if err != nil {
		log.FATAL.Println(err)
		return 20
	}

	for {
		cm, err := readStoredMeasure()

		// Empty state of the repository - no stored metrics.
		if err == io.EOF {
			break
		} else if err != nil {
			log.FATAL.Println(err)
			return 40
		}

		out := csv.NewWriter(output)

		for _, measure := range cm.Measures {
			out.Write([]string{cm.Timestamp.String(), measure.Name, strconv.Itoa(measure.Value), strconv.Itoa(measure.Baseline)})
		}
		out.Flush()
	}

	log.INFO.Println("Finished reading measures stored in git")
	return 0
}
Пример #2
0
func Check(prefix string, slack int, write bool, inputType string, zeroOnMissing bool, input io.Reader) int {
	// Parse the measures from stdin
	log.INFO.Println("Parsing measures from stdin")
	passedMeasures, err := store.ParseMeasures(input, store.ParseInputType(inputType))
	log.INFO.Println("Finished parsing measures from stdin")
	log.INFO.Println(passedMeasures)
	if err != nil {
		log.FATAL.Println(err)
		return 10
	}

	log.INFO.Println("Reading measures stored in git")
	gitlog := store.CommitMeasureCommand(prefix)
	var stderr bytes.Buffer
	gitlog.Stderr = &stderr

	readStoredMeasure, err := store.CommitMeasures(gitlog)
	if err != nil {
		log.FATAL.Println(err)
		return 20
	}

	commitmeasure, err := readStoredMeasure()

	// Empty state of the repository - no stored metrics. Let's store one if we can.
	if err == io.EOF {
		log.INFO.Println("No measures found.")
		if write {
			log.INFO.Println("Writing initial measure values.")
			err = store.PutMeasures(prefix, passedMeasures)
			if err != nil {
				log.FATAL.Println(err)
				return 30
			}
			log.INFO.Println("Successfully written initial measures.")
		}
	} else if err != nil {
		log.FATAL.Println(err)
		return 40
	} else {
		log.INFO.Println("Checking passed measure against stored value")
		finalMeasures, compareErr := store.CompareMeasures(prefix, commitmeasure.CommitHash, commitmeasure.Measures, passedMeasures, slack, zeroOnMissing)

		if write {
			log.INFO.Println("Writing measure values.")
			err = store.PutMeasures(prefix, finalMeasures)
			if err != nil {
				log.FATAL.Println(err)
				return 30
			}
			log.INFO.Println("Successfully written measures.")
		}
		if compareErr != nil {
			log.FATAL.Println(compareErr)
			return 50
		} else {
			log.INFO.Println("Metrics passing!")
		}
	}

	log.INFO.Println("Finished reading measures stored in git")
	return 0
}