API version checking and linting.
This commit is contained in:
@@ -14,19 +14,16 @@ import (
|
||||
// Application is a thing that responsible for all application-related
|
||||
// actions like data fetching, storing, etc. on higher level.
|
||||
type Application struct {
|
||||
config *Config
|
||||
ctx context.Context
|
||||
doneChan chan struct{}
|
||||
logger *logger.Logger
|
||||
name string
|
||||
|
||||
storage storage.Metrics
|
||||
storageDone chan struct{}
|
||||
|
||||
fetchIsRunning bool
|
||||
ctx context.Context
|
||||
storage storage.Metrics
|
||||
config *Config
|
||||
doneChan chan struct{}
|
||||
logger *logger.Logger
|
||||
storageDone chan struct{}
|
||||
httpClient *http.Client
|
||||
name string
|
||||
fetchIsRunningMutex sync.RWMutex
|
||||
|
||||
httpClient *http.Client
|
||||
fetchIsRunning bool
|
||||
}
|
||||
|
||||
// NewApplication creates new application.
|
||||
|
@@ -4,11 +4,11 @@ import "time"
|
||||
|
||||
// Config is a generic application configuration.
|
||||
type Config struct {
|
||||
// Headers is a list of headers that should be added to metrics request.
|
||||
Headers map[string]string `yaml:"headers"`
|
||||
// Endpoint is a remote application endpoint which should give us metrics
|
||||
// in Prometheus format.
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
// Headers is a list of headers that should be added to metrics request.
|
||||
Headers map[string]string `yaml:"headers"`
|
||||
// TimeBetweenRequests is a minimal amount of time which should pass
|
||||
// between requests.
|
||||
TimeBetweenRequests time.Duration `yaml:"time_between_requests"`
|
||||
|
@@ -29,6 +29,7 @@ func (a *Application) parse(body string) map[string]models.Metric {
|
||||
a.logger.Debugln("Analyzing line:", line)
|
||||
|
||||
name = a.getMetricName(line)
|
||||
|
||||
metric, found := data[name]
|
||||
if !found {
|
||||
metric = models.NewMetric(name, "", "", nil)
|
||||
@@ -53,9 +54,9 @@ func (a *Application) parse(body string) map[string]models.Metric {
|
||||
|
||||
data[name] = metric
|
||||
|
||||
// According to https://github.com/Showmax/prometheus-docs/blob/master/content/docs/instrumenting/exposition_formats.md
|
||||
// HELP and TYPE lines should be printed before actual metric. Do not even
|
||||
// According to docs HELP and TYPE lines should be printed before actual metric. Do not even
|
||||
// report bugs regarding that!
|
||||
// Docs: https://github.com/Showmax/prometheus-docs/blob/master/content/docs/instrumenting/exposition_formats.md
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -76,12 +77,12 @@ func (a *Application) parse(body string) map[string]models.Metric {
|
||||
|
||||
metric.Value = a.getMetricValue(line)
|
||||
|
||||
a.logger.Debugln("Got metric: %+v\n", metric)
|
||||
a.logger.Debugf("Got metric: %+v\n", metric)
|
||||
|
||||
data[name] = metric
|
||||
}
|
||||
|
||||
a.logger.Debugln("Data parsed: %+v\n", data)
|
||||
a.logger.Debugf("Data parsed: %+v\n", data)
|
||||
|
||||
return data
|
||||
}
|
||||
@@ -138,7 +139,7 @@ func (a *Application) getParametersForPrometheusMetric(line string) []string {
|
||||
}
|
||||
|
||||
// Sometimes nestif causes questions, like here. Is code below is
|
||||
// "deply nested"? I think not. So:
|
||||
// "deeply nested"? I think not. So:
|
||||
// nolint:nestif
|
||||
if !paramNameFinished {
|
||||
if string(r) != "=" {
|
||||
|
Reference in New Issue
Block a user