예제 #1
0
func (r *S3Reporter) SpecDidComplete(specSummary *ginkgotypes.SpecSummary) {
	if specSummary.Passed() && specSummary.IsMeasurement {
		for _, measurement := range specSummary.Measurements {
			if measurement.Info == nil {
				panic(fmt.Sprintf("%#v", specSummary))
			}

			info, ok := measurement.Info.(ReporterInfo)
			if !ok {
				r.logger.Error("failed-type-assertion-on-measurement-info", errors.New("type-assertion-failed"))
				continue
			}

			if info.MetricName == "" {
				r.logger.Error("failed-blank-metric-name", errors.New("blank-metric-name"))
				continue
			}

			now := time.Now()
			data := Data{
				Timestamp:   now.Unix(),
				Measurement: *measurement,
			}

			dataJSON, err := json.Marshal(data)
			if err != nil {
				r.logger.Error("failed-marshaling-data", err)
				continue
			}

			measurementData := string(dataJSON)
			key := fmt.Sprintf("%s/%s-%s", startTime, info.MetricName, now.Format(time.RFC3339))

			_, err = r.uploader.Upload(&s3manager.UploadInput{
				Bucket: aws.String(r.bucketName),
				Key:    aws.String(key),
				Body:   bytes.NewReader([]byte(measurementData)),
			})

			if err != nil {
				r.logger.Error("failed-uploading-metric-to-s3", err)
				continue
			}

			r.logger.Debug("successfully-uploaded-metric-to-s3", lager.Data{
				"bucket-name": r.bucketName,
				"key":         key,
				"content":     measurementData,
			})
		}
	}
}
예제 #2
0
func (r *DataDogReporter) SpecDidComplete(specSummary *types.SpecSummary) {
	if specSummary.Passed() && specSummary.IsMeasurement {
		for _, measurement := range specSummary.Measurements {
			if measurement.Info == nil {
				panic(fmt.Sprintf("%#v", specSummary))
			}

			info, ok := measurement.Info.(ReporterInfo)
			if !ok {
				r.logger.Error("failed-type-assertion-on-measurement-info", errors.New("type-assertion-failed"))
				continue
			}

			if info.MetricName == "" {
				r.logger.Error("failed-blank-metric-name", errors.New("blank-metric-name"))
				continue
			}

			timestamp := float64(time.Now().Unix())
			r.logger.Info("sending-metrics-to-datadog", lager.Data{"metric": info.MetricName, "prefix": r.metricPrefix})
			err := r.dataDogClient.PostMetrics([]datadog.Metric{
				{
					Metric: fmt.Sprintf("%s.%s", r.metricPrefix, info.MetricName),
					Points: []datadog.DataPoint{
						{timestamp, measurement.Average},
					},
				},
			})
			if err != nil {
				r.logger.Error("failed-sending-metrics-to-datadog", err, lager.Data{"metric": info.MetricName, "prefix": r.metricPrefix})
				continue
			}
			r.logger.Info("sending-metrics-to-datadog-complete", lager.Data{"metric": info.MetricName, "prefix": r.metricPrefix})
		}
	}
}