func (s *ManifestDeployerSuite) assertCharm(c *gc.C, revision int, content ...ft.Entry) { url, err := charm.ReadCharmURL(filepath.Join(s.targetPath, ".juju-charm")) c.Assert(err, gc.IsNil) c.Assert(url, gc.DeepEquals, charmURL(revision)) ft.Entries(content).Check(c, s.targetPath) }
) var ( logger = loggo.GetLogger("juju.worker.metrics.collect") // errMetricsNotDefined is returned when the charm the uniter is running does // not declared any metrics. errMetricsNotDefined = errors.New("no metrics defined") // readCharm function reads the charm directory and extracts declared metrics and the charm url. readCharm = func(unitTag names.UnitTag, paths context.Paths) (*corecharm.URL, map[string]corecharm.Metric, error) { ch, err := corecharm.ReadCharm(paths.GetCharmDir()) if err != nil { return nil, nil, errors.Annotatef(err, "failed to read charm from: %v", paths.GetCharmDir()) } chURL, err := charm.ReadCharmURL(path.Join(paths.GetCharmDir(), charm.CharmURLPath)) if err != nil { return nil, nil, errors.Trace(err) } charmMetrics := map[string]corecharm.Metric{} if ch.Metrics() != nil { charmMetrics = ch.Metrics().Metrics } return chURL, charmMetrics, nil } // newRecorder returns a struct that implements the spool.MetricRecorder // interface. newRecorder = func(unitTag names.UnitTag, paths context.Paths, metricFactory spool.MetricFactory) (spool.MetricRecorder, error) { chURL, charmMetrics, err := readCharm(unitTag, paths) if err != nil {