From 717b0a7aee1fc52f54057eac57ea896850085b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Simas?= Date: Mon, 1 Jul 2024 08:59:03 -0300 Subject: [PATCH] docs: add missing function documentation --- internal/collector/collector.go | 5 +++++ internal/collector/note.go | 1 + internal/storage/influxdb.go | 1 + internal/zettelkasten/git.go | 3 +-- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/collector/collector.go b/internal/collector/collector.go index ca5c2b1..7fa9cf1 100644 --- a/internal/collector/collector.go +++ b/internal/collector/collector.go @@ -16,11 +16,13 @@ type CollectorConfig struct { IgnorePatterns []string } +// Collector represents a metrics collector. type Collector struct { config CollectorConfig storage storage.Storage } +// NewCollector creates a new collector func NewCollector(ignorePatterns []string, storage storage.Storage) Collector { return Collector{ config: CollectorConfig{ @@ -30,6 +32,7 @@ func NewCollector(ignorePatterns []string, storage storage.Storage) Collector { } } +// CollectMetrics collects all metrics from a Zettelkasten rooted in `root` and writes them to the storage with a timestamp of `collectionTime`. func (c *Collector) CollectMetrics(root fs.FS, collectionTime time.Time) error { slog.Debug("Collecting metrics", slog.Time("collection_time", collectionTime)) start := time.Now() @@ -38,6 +41,7 @@ func (c *Collector) CollectMetrics(root fs.FS, collectionTime time.Time) error { return err } + // Write metrics to storage for name, metric := range collected.Notes { c.storage.WriteMetric(name, metric, collectionTime) } @@ -46,6 +50,7 @@ func (c *Collector) CollectMetrics(root fs.FS, collectionTime time.Time) error { return nil } +// collectMetrics collects all metrics from a Zettelkasten rooted in `root`. func (c *Collector) collectMetrics(root fs.FS) (metrics.Metrics, error) { var noteCount uint var linkCount uint diff --git a/internal/collector/note.go b/internal/collector/note.go index dde830a..15637a6 100644 --- a/internal/collector/note.go +++ b/internal/collector/note.go @@ -21,6 +21,7 @@ var md = goldmark.New( ), ) +// CollectNoteMetrics collects all note metrics from a note with the given `content`. func CollectNoteMetrics(content []byte) metrics.NoteMetrics { noteMetrics := metrics.NoteMetrics{ Links: make(map[string]uint), diff --git a/internal/storage/influxdb.go b/internal/storage/influxdb.go index ca12025..56bad78 100644 --- a/internal/storage/influxdb.go +++ b/internal/storage/influxdb.go @@ -25,6 +25,7 @@ func NewInfluxDBStorage(url, org, bucket, token string) InfluxDBStorage { return InfluxDBStorage{writeAPI: writeAPI, queryAPI: queryAPI} } +// WriteMetric writes `metric` for `noteName` to the storage with `timestamp`. func (i InfluxDBStorage) WriteMetric(noteName string, metric metrics.NoteMetrics, timestamp time.Time) { point := influxdb2.NewPoint( measurementName, diff --git a/internal/zettelkasten/git.go b/internal/zettelkasten/git.go index ccf1d1f..a380fc9 100644 --- a/internal/zettelkasten/git.go +++ b/internal/zettelkasten/git.go @@ -30,8 +30,7 @@ func (g GitZettelkasten) GetRoot() fs.FS { return os.DirFS(g.rootPath) } -// Ensure makes sure that the git repository is valid and updated with the -// latest changes from the remote. +// Ensure makes sure that the git repository is valid and updated with the latest changes from the remote. func (g GitZettelkasten) Ensure() error { f, err := os.Stat(g.rootPath) if errors.Is(err, fs.ErrNotExist) {