Skip to content

Commit

Permalink
docs: add missing function documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
luissimas committed Jul 1, 2024
1 parent b88e117 commit 717b0a7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()
Expand All @@ -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)
}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/collector/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions internal/storage/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions internal/zettelkasten/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 717b0a7

Please sign in to comment.