// checkCache checks the cache for metric types. // returns: // - array of metrics that need to be collected // - array of metrics that were returned from the cache func checkCache(mts []core.Metric) ([]plugin.PluginMetricType, []core.Metric) { var fromCache []core.Metric var metricsToCollect []plugin.PluginMetricType for _, mt := range mts { if m := metricCache.get(core.JoinNamespace(mt.Namespace()), mt.Version()); m != nil { switch metric := m.(type) { case core.Metric: fromCache = append(fromCache, metric) case []core.Metric: for _, met := range metric { fromCache = append(fromCache, met) } default: log.WithFields(log.Fields{ "_module": "client", "_block": "checkCache", }).Error("unsupported type found in the cache") } } else { mt := plugin.PluginMetricType{ Namespace_: mt.Namespace(), LastAdvertisedTime_: mt.LastAdvertisedTime(), Version_: mt.Version(), Tags_: mt.Tags(), Labels_: mt.Labels(), Config_: mt.Config(), } metricsToCollect = append(metricsToCollect, mt) } } return metricsToCollect, fromCache }