Skip to content

Commit

Permalink
simplify stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jakthom committed Oct 31, 2024
1 parent 857a6c4 commit 5a2d3c3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 50 deletions.
2 changes: 1 addition & 1 deletion hercules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ packages:
yo: yee # Inject these variables to the package definition
metricPrefix: skt_ # Prefix all metrics with this
- package: hercules-packages/example/us-zips/1.0.yml
- package: hercules-packages/example/nyc-taxi/1.0.yml
# - package: hercules-packages/example/nyc-taxi/1.0.yml
1 change: 0 additions & 1 deletion pkg/herculesPackage/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func (p *PackageConfig) getFromEndpoint() (Package, error) {
}

func (p *PackageConfig) getFromObjectStorage() (Package, error) {
// log.Debug().Interface("package", p.Package).Msg("loading " + p.Package + " package from object storage")
log.Fatal().Interface("package", p.Package).Msg("object storage-backed packages are not yet supported")
pkg := Package{}
return pkg, nil
Expand Down
8 changes: 2 additions & 6 deletions pkg/metrics/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import (
"github.com/rs/zerolog/log"
)

type CounterMetricDefinition struct {
metricDefinition `mapstructure:",squash"`
}

type CounterMetric struct {
Definition CounterMetricDefinition
Definition MetricDefinition
GlobalLabels labels.Labels
Collector *prometheus.CounterVec
}
Expand Down Expand Up @@ -59,7 +55,7 @@ func (m *CounterMetric) MaterializeWithConnection(conn *sql.Conn) error {
return nil
}

func NewCounterMetric(definition CounterMetricDefinition, meta herculestypes.MetricMetadata) CounterMetric {
func NewCounterMetric(definition MetricDefinition, meta herculestypes.MetricMetadata) CounterMetric {
// TODO! Turn this into a generic function instead of copy/pasta
definition.Name = meta.Prefix() + definition.Name
metric := CounterMetric{
Expand Down
8 changes: 2 additions & 6 deletions pkg/metrics/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import (
"github.com/rs/zerolog/log"
)

type GaugeMetricDefinition struct {
metricDefinition `mapstructure:",squash"`
}

type GaugeMetric struct {
Definition GaugeMetricDefinition
Definition MetricDefinition
GlobalLabels labels.Labels
Collector *prometheus.GaugeVec
}
Expand Down Expand Up @@ -60,7 +56,7 @@ func (m *GaugeMetric) MaterializeWithConnection(conn *sql.Conn) error {
return nil
}

func NewGaugeMetric(definition GaugeMetricDefinition, meta herculestypes.MetricMetadata) GaugeMetric {
func NewGaugeMetric(definition MetricDefinition, meta herculestypes.MetricMetadata) GaugeMetric {
// TODO! Turn this into a generic function instead of copy/pasta
definition.Name = meta.Prefix() + definition.Name
metric := GaugeMetric{
Expand Down
9 changes: 2 additions & 7 deletions pkg/metrics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import (
"github.com/rs/zerolog/log"
)

type HistogramMetricDefinition struct {
metricDefinition `mapstructure:",squash"`
Buckets []float64
}

type HistogramMetric struct {
Definition HistogramMetricDefinition
Definition MetricDefinition
GlobalLabels labels.Labels
Collector *prometheus.HistogramVec
}
Expand Down Expand Up @@ -61,7 +56,7 @@ func (m *HistogramMetric) MaterializeWithConnection(conn *sql.Conn) error {
return nil
}

func NewHistogramMetric(definition HistogramMetricDefinition, meta herculestypes.MetricMetadata) HistogramMetric {
func NewHistogramMetric(definition MetricDefinition, meta herculestypes.MetricMetadata) HistogramMetric {
// TODO! Turn this into a generic function instead of copy/pasta
definition.Name = meta.Prefix() + definition.Name
metric := HistogramMetric{
Expand Down
35 changes: 13 additions & 22 deletions pkg/metrics/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,17 @@ import (
"github.com/rs/zerolog/log"
)

type MetricType string

const (
// Metric Types
CounterMetricType MetricType = "counter"
GaugeMetricType MetricType = "gauge"
HistogramMetricType MetricType = "histogram"
SummaryMetricType MetricType = "summary"
)

type metricDefinition struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
Type MetricType `json:"type"`
Help string `json:"help"`
Sql db.Sql `json:"sql"`
Labels []string `json:"labels"`
type MetricDefinition struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
Help string `json:"help"`
Sql db.Sql `json:"sql"`
Labels []string `json:"labels"`
Buckets []float64 `json:"buckets"` // If the metric is a histogram
Objectives []float64 `json:"objectives"` // If the metric is a summary
}

func (md *metricDefinition) materializeWithConnection(conn *sql.Conn) ([]QueryResult, error) {
func (md *MetricDefinition) materializeWithConnection(conn *sql.Conn) ([]QueryResult, error) {
rows, _ := db.RunSqlQuery(conn, md.Sql)
var queryResults []QueryResult
columns, _ := rows.Columns()
Expand Down Expand Up @@ -58,10 +49,10 @@ func (md *metricDefinition) materializeWithConnection(conn *sql.Conn) ([]QueryRe
}

type MetricDefinitions struct {
Gauge []GaugeMetricDefinition `json:"gauge"`
Counter []CounterMetricDefinition `json:"counter"`
Summary []SummaryMetricDefinition `json:"summary"`
Histogram []HistogramMetricDefinition `json:"histogram"`
Gauge []MetricDefinition `json:"gauge"`
Counter []MetricDefinition `json:"counter"`
Summary []MetricDefinition `json:"summary"`
Histogram []MetricDefinition `json:"histogram"`
}

func (m *MetricDefinitions) Merge(metricDefinitions MetricDefinitions) {
Expand Down
9 changes: 2 additions & 7 deletions pkg/metrics/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import (
"github.com/rs/zerolog/log"
)

type SummaryMetricDefinition struct {
metricDefinition `mapstructure:",squash"`
Objectives []float64
}

type SummaryMetric struct {
Definition SummaryMetricDefinition
Definition MetricDefinition
GlobalLabels labels.Labels
Collector *prometheus.SummaryVec
}
Expand Down Expand Up @@ -65,7 +60,7 @@ func (m *SummaryMetric) MaterializeWithConnection(conn *sql.Conn) error {
return nil
}

func NewSummaryMetric(definition SummaryMetricDefinition, meta herculestypes.MetricMetadata) SummaryMetric {
func NewSummaryMetric(definition MetricDefinition, meta herculestypes.MetricMetadata) SummaryMetric {
// TODO! Turn this into a generic function instead of copy/pasta
definition.Name = meta.Prefix() + definition.Name
metric := SummaryMetric{
Expand Down

0 comments on commit 5a2d3c3

Please sign in to comment.