// Register returns the correct MetricInfo instance from the pool for // passed in metric and type. Register will always return a non nil value. func (m *metricInfoStoreType) Register( metric *metrics.Value, kind, subType types.Type) ( result *MetricInfo) { if kind == types.Unknown { panic("Got Unknown type") } if kind.UsesSubType() && subType == types.Unknown { panic("Got unknown sub-type when it is required") } var ranges *Ranges var isNotCumulative bool if kind == types.Dist { // TODO: Maybe later this shouldn't be tricorder specific, // but for now tricorder is the only thing we know that // has distributions. distribution := metric.Value.(*messages.Distribution) isNotCumulative = distribution.IsNotCumulative upperLimitSlice := distExtractUpperLimits(distribution) ranges = m.rangesCache.Get(metric.Path, upperLimitSlice) } infoStruct := MetricInfo{ path: metric.Path, description: metric.Description, unit: metric.Unit, kind: kind, subType: subType, ranges: ranges, isNotCumulative: isNotCumulative, groupId: metric.GroupId} result, alreadyExists := m.ByInfo[infoStruct] if alreadyExists { return } result = &infoStruct m.ByInfo[infoStruct] = result m.ByName[infoStruct.path] = append(m.ByName[infoStruct.path], result) return }