Add documentation

This commit is contained in:
Jan Gräfen 2021-03-05 19:53:37 +01:00
parent f96fd1b23c
commit de4833ebe1
8 changed files with 19 additions and 8 deletions

View file

@ -12,9 +12,13 @@ var (
ctx = context.Background()
)
// Fetcher defines a common interface for types that fetch pricing data from the HCloud API.
type Fetcher interface {
// GetHourly returns the prometheus collector that collects pricing data for hourly expenses.
GetHourly() prometheus.Collector
// GetMonthly returns the prometheus collector that collects pricing data for monthly expenses.
GetMonthly() prometheus.Collector
// Run executes a new data fetching cycle and updates the prometheus exposed collectors.
Run(*hcloud.Client) error
}
@ -31,7 +35,7 @@ func (fetcher baseFetcher) GetMonthly() prometheus.Collector {
return fetcher.monthly
}
func new(resource string, additionalLabels ...string) *baseFetcher {
func newBase(resource string, additionalLabels ...string) *baseFetcher {
labels := []string{"name"}
labels = append(labels, additionalLabels...)

View file

@ -10,8 +10,9 @@ const (
var _ Fetcher = &floatingIP{}
// NewFloatingIP creates a new fetcher that will collect pricing information on floating IPs.
func NewFloatingIP() Fetcher {
return &floatingIP{new("floatingip", "location")}
return &floatingIP{newBase("floatingip", "location")}
}
type floatingIP struct {

View file

@ -8,8 +8,9 @@ import (
var _ Fetcher = &loadBalancer{}
// NewLoadbalancer creates a new fetcher that will collect pricing information on load balancers.
func NewLoadbalancer() Fetcher {
return &loadBalancer{new("loadbalancer", "location", "type")}
return &loadBalancer{newBase("loadbalancer", "location", "type")}
}
type loadBalancer struct {

View file

@ -8,8 +8,9 @@ import (
var _ Fetcher = &server{}
// NewServer creates a new fetcher that will collect pricing information on servers.
func NewServer() Fetcher {
return &server{new("server", "location")}
return &server{newBase("server", "location")}
}
type server struct {

View file

@ -12,8 +12,9 @@ const (
var _ Fetcher = &server{}
// NewServerBackup creates a new fetcher that will collect pricing information on server backups.
func NewServerBackup() Fetcher {
return &serverBackup{new("server_backup", "location", "type")}
return &serverBackup{newBase("server_backup", "location", "type")}
}
type serverBackup struct {

View file

@ -12,8 +12,9 @@ const (
var _ Fetcher = &serverTraffic{}
// NewServerTraffic creates a new fetcher that will collect pricing information on server traffic.
func NewServerTraffic() Fetcher {
return &serverTraffic{new("server_traffic", "location", "type")}
return &serverTraffic{newBase("server_traffic", "location", "type")}
}
type serverTraffic struct {

View file

@ -12,8 +12,9 @@ const (
var _ Fetcher = &snapshot{}
// NewSnapshot creates a new fetcher that will collect pricing information on server snapshots.
func NewSnapshot() Fetcher {
return &snapshot{new("snapshot")}
return &snapshot{newBase("snapshot")}
}
type snapshot struct {

View file

@ -13,8 +13,9 @@ const (
var _ Fetcher = &volume{}
// NewVolume creates a new fetcher that will collect pricing information on volumes.
func NewVolume() Fetcher {
return &server{new("volume", "location", "bytes")}
return &server{newBase("volume", "location", "bytes")}
}
type volume struct {