in custom-metrics-stackdriver-adapter/pkg/adapter/translator/response_translator_core.go [46:87]
func (r *PodResult) AddCoreContainerMetricFromResponse(response *stackdriver.ListTimeSeriesResponse) error {
for _, series := range response.TimeSeries {
if len(series.Points) <= 0 {
// This shouldn't happen with correct query to Stackdriver
return apierr.NewInternalError(fmt.Errorf("Empty time series returned from Stackdriver"))
}
// TODO(holubowicz): consider changing request window for core metrics
// Points in a time series are returned in reverse time order
point := *series.Points[0]
metricValue, err := getQuantityValue(point)
if err != nil {
return err
}
podKey, err := r.metricKey(series, PodSchemaKey)
if err != nil {
return err
}
_, ok := r.ContainerMetric[podKey]
if !ok {
r.ContainerMetric[podKey] = make(map[string]resource.Quantity, 0)
intervalEndTime, err := time.Parse(time.RFC3339, point.Interval.EndTime)
if err != nil {
return err
}
r.TimeInfo[podKey] = api.TimeInfo{Timestamp: intervalEndTime, Window: r.alignmentPeriod}
}
containerName, ok := series.Resource.Labels["container_name"]
if !ok {
return apierr.NewInternalError(fmt.Errorf("Container name is not present."))
}
_, ok = r.ContainerMetric[podKey][containerName]
if ok {
return apierr.NewInternalError(fmt.Errorf("The same container appered two time in the response."))
}
r.ContainerMetric[podKey][containerName] = *metricValue
}
return nil
}