From b75428ec19d6f49dbf23f11510e3411fb7df35d7 Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Thu, 1 Feb 2018 09:55:07 +0000 Subject: [PATCH 1/2] rename package retrieve to scrape no fucnctinal changes just renaming retrieval to scrape --- cmd/prometheus/main.go | 4 ++-- discovery/file/file.go | 2 +- pkg/relabel/relabel.go | 2 +- relabel/relabel.go | 2 +- {retrieval => scrape}/helpers_test.go | 2 +- {retrieval => scrape}/manager.go | 2 +- {retrieval => scrape}/manager_test.go | 2 +- {retrieval => scrape}/scrape.go | 2 +- {retrieval => scrape}/scrape_test.go | 2 +- {retrieval => scrape}/target.go | 2 +- {retrieval => scrape}/target_test.go | 2 +- .../testdata/bearertoken.txt | 0 {retrieval => scrape}/testdata/ca.cer | 0 {retrieval => scrape}/testdata/ca.key | 0 {retrieval => scrape}/testdata/client.cer | 0 {retrieval => scrape}/testdata/client.key | 0 {retrieval => scrape}/testdata/server.cer | 0 {retrieval => scrape}/testdata/server.key | 0 {retrieval => scrape}/testdata/servername.cer | 0 {retrieval => scrape}/testdata/servername.key | 0 storage/remote/write.go | 2 +- web/api/v1/api.go | 10 ++++---- web/api/v1/api_test.go | 12 +++++----- web/api/v2/api.go | 6 ++--- web/web.go | 24 +++++++++---------- 25 files changed, 39 insertions(+), 39 deletions(-) rename {retrieval => scrape}/helpers_test.go (99%) rename {retrieval => scrape}/manager.go (99%) rename {retrieval => scrape}/manager_test.go (99%) rename {retrieval => scrape}/scrape.go (99%) rename {retrieval => scrape}/scrape_test.go (99%) rename {retrieval => scrape}/target.go (99%) rename {retrieval => scrape}/target_test.go (99%) rename {retrieval => scrape}/testdata/bearertoken.txt (100%) rename {retrieval => scrape}/testdata/ca.cer (100%) rename {retrieval => scrape}/testdata/ca.key (100%) rename {retrieval => scrape}/testdata/client.cer (100%) rename {retrieval => scrape}/testdata/client.key (100%) rename {retrieval => scrape}/testdata/server.cer (100%) rename {retrieval => scrape}/testdata/server.key (100%) rename {retrieval => scrape}/testdata/servername.cer (100%) rename {retrieval => scrape}/testdata/servername.key (100%) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index c090313b97..c60a0c335c 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -50,8 +50,8 @@ import ( sd_config "github.com/prometheus/prometheus/discovery/config" "github.com/prometheus/prometheus/notifier" "github.com/prometheus/prometheus/promql" - "github.com/prometheus/prometheus/retrieval" "github.com/prometheus/prometheus/rules" + "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage/remote" "github.com/prometheus/prometheus/storage/tsdb" @@ -246,7 +246,7 @@ func main() { ctxNotify, cancelNotify = context.WithCancel(context.Background()) discoveryManagerNotify = discovery.NewManager(ctxNotify, log.With(logger, "component", "discovery manager notify")) - scrapeManager = retrieval.NewManager(log.With(logger, "component", "scrape manager"), fanoutStorage) + scrapeManager = scrape.NewManager(log.With(logger, "component", "scrape manager"), fanoutStorage) queryEngine = promql.NewEngine(fanoutStorage, &cfg.queryEngine) ruleManager = rules.NewManager(&rules.ManagerOptions{ Appendable: fanoutStorage, diff --git a/discovery/file/file.go b/discovery/file/file.go index eaba2df6ff..cf1e1deb00 100644 --- a/discovery/file/file.go +++ b/discovery/file/file.go @@ -389,7 +389,7 @@ func (d *Discovery) readFile(filename string) ([]*targetgroup.Group, error) { return nil, err } default: - panic(fmt.Errorf("retrieval.FileDiscovery.readFile: unhandled file extension %q", ext)) + panic(fmt.Errorf("discovery.File.readFile: unhandled file extension %q", ext)) } for i, tg := range targetGroups { diff --git a/pkg/relabel/relabel.go b/pkg/relabel/relabel.go index 775051474c..4f215ca7fc 100644 --- a/pkg/relabel/relabel.go +++ b/pkg/relabel/relabel.go @@ -96,7 +96,7 @@ func relabel(lset labels.Labels, cfg *config.RelabelConfig) labels.Labels { } } default: - panic(fmt.Errorf("retrieval.relabel: unknown relabel action type %q", cfg.Action)) + panic(fmt.Errorf("relabel: unknown relabel action type %q", cfg.Action)) } return lb.Labels() diff --git a/relabel/relabel.go b/relabel/relabel.go index 49e134c131..d506620f1d 100644 --- a/relabel/relabel.go +++ b/relabel/relabel.go @@ -99,7 +99,7 @@ func relabel(labels model.LabelSet, cfg *config.RelabelConfig) model.LabelSet { } } default: - panic(fmt.Errorf("retrieval.relabel: unknown relabel action type %q", cfg.Action)) + panic(fmt.Errorf("relabel: unknown relabel action type %q", cfg.Action)) } return labels } diff --git a/retrieval/helpers_test.go b/scrape/helpers_test.go similarity index 99% rename from retrieval/helpers_test.go rename to scrape/helpers_test.go index 018bf9c197..f1e5471dfe 100644 --- a/retrieval/helpers_test.go +++ b/scrape/helpers_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package retrieval +package scrape import ( "github.com/prometheus/prometheus/pkg/labels" diff --git a/retrieval/manager.go b/scrape/manager.go similarity index 99% rename from retrieval/manager.go rename to scrape/manager.go index 3fb88cb7bc..356f1d8627 100644 --- a/retrieval/manager.go +++ b/scrape/manager.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package retrieval +package scrape import ( "fmt" diff --git a/retrieval/manager_test.go b/scrape/manager_test.go similarity index 99% rename from retrieval/manager_test.go rename to scrape/manager_test.go index a4f2df96ea..94d2f41f6c 100644 --- a/retrieval/manager_test.go +++ b/scrape/manager_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package retrieval +package scrape import ( "fmt" diff --git a/retrieval/scrape.go b/scrape/scrape.go similarity index 99% rename from retrieval/scrape.go rename to scrape/scrape.go index d13aa3b2b3..5c5a71b00c 100644 --- a/retrieval/scrape.go +++ b/scrape/scrape.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package retrieval +package scrape import ( "bufio" diff --git a/retrieval/scrape_test.go b/scrape/scrape_test.go similarity index 99% rename from retrieval/scrape_test.go rename to scrape/scrape_test.go index b63959767b..61284059b9 100644 --- a/retrieval/scrape_test.go +++ b/scrape/scrape_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package retrieval +package scrape import ( "bytes" diff --git a/retrieval/target.go b/scrape/target.go similarity index 99% rename from retrieval/target.go rename to scrape/target.go index 900ddb632b..948d861361 100644 --- a/retrieval/target.go +++ b/scrape/target.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package retrieval +package scrape import ( "errors" diff --git a/retrieval/target_test.go b/scrape/target_test.go similarity index 99% rename from retrieval/target_test.go rename to scrape/target_test.go index a21f3fcbfa..bee0ad1ebd 100644 --- a/retrieval/target_test.go +++ b/scrape/target_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package retrieval +package scrape import ( "crypto/tls" diff --git a/retrieval/testdata/bearertoken.txt b/scrape/testdata/bearertoken.txt similarity index 100% rename from retrieval/testdata/bearertoken.txt rename to scrape/testdata/bearertoken.txt diff --git a/retrieval/testdata/ca.cer b/scrape/testdata/ca.cer similarity index 100% rename from retrieval/testdata/ca.cer rename to scrape/testdata/ca.cer diff --git a/retrieval/testdata/ca.key b/scrape/testdata/ca.key similarity index 100% rename from retrieval/testdata/ca.key rename to scrape/testdata/ca.key diff --git a/retrieval/testdata/client.cer b/scrape/testdata/client.cer similarity index 100% rename from retrieval/testdata/client.cer rename to scrape/testdata/client.cer diff --git a/retrieval/testdata/client.key b/scrape/testdata/client.key similarity index 100% rename from retrieval/testdata/client.key rename to scrape/testdata/client.key diff --git a/retrieval/testdata/server.cer b/scrape/testdata/server.cer similarity index 100% rename from retrieval/testdata/server.cer rename to scrape/testdata/server.cer diff --git a/retrieval/testdata/server.key b/scrape/testdata/server.key similarity index 100% rename from retrieval/testdata/server.key rename to scrape/testdata/server.key diff --git a/retrieval/testdata/servername.cer b/scrape/testdata/servername.cer similarity index 100% rename from retrieval/testdata/servername.cer rename to scrape/testdata/servername.cer diff --git a/retrieval/testdata/servername.key b/scrape/testdata/servername.key similarity index 100% rename from retrieval/testdata/servername.key rename to scrape/testdata/servername.key diff --git a/storage/remote/write.go b/storage/remote/write.go index 2687b9d83e..7427b3bbb8 100644 --- a/storage/remote/write.go +++ b/storage/remote/write.go @@ -19,7 +19,7 @@ import ( "github.com/prometheus/prometheus/storage" ) -// Appender implements retrieval.Appendable. +// Appender implements scrape.Appendable. func (s *Storage) Appender() (storage.Appender, error) { return s, nil } diff --git a/web/api/v1/api.go b/web/api/v1/api.go index e18137d06a..523316c901 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -38,7 +38,7 @@ import ( "github.com/prometheus/prometheus/pkg/timestamp" "github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/promql" - "github.com/prometheus/prometheus/retrieval" + "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage/remote" "github.com/prometheus/prometheus/util/httputil" @@ -82,7 +82,7 @@ func (e *apiError) Error() string { } type targetRetriever interface { - Targets() []*retrieval.Target + Targets() []*scrape.Target } type alertmanagerRetriever interface { @@ -428,9 +428,9 @@ type Target struct { ScrapeURL string `json:"scrapeUrl"` - LastError string `json:"lastError"` - LastScrape time.Time `json:"lastScrape"` - Health retrieval.TargetHealth `json:"health"` + LastError string `json:"lastError"` + LastScrape time.Time `json:"lastScrape"` + Health scrape.TargetHealth `json:"health"` } // TargetDiscovery has all the active targets. diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index 425e0aafbf..9b6ebe5424 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -38,13 +38,13 @@ import ( "github.com/prometheus/prometheus/pkg/timestamp" "github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/promql" - "github.com/prometheus/prometheus/retrieval" + "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage/remote" ) -type targetRetrieverFunc func() []*retrieval.Target +type targetRetrieverFunc func() []*scrape.Target -func (f targetRetrieverFunc) Targets() []*retrieval.Target { +func (f targetRetrieverFunc) Targets() []*scrape.Target { return f() } @@ -81,9 +81,9 @@ func TestEndpoints(t *testing.T) { now := time.Now() - tr := targetRetrieverFunc(func() []*retrieval.Target { - return []*retrieval.Target{ - retrieval.NewTarget( + tr := targetRetrieverFunc(func() []*scrape.Target { + return []*scrape.Target{ + scrape.NewTarget( labels.FromMap(map[string]string{ model.SchemeLabel: "http", model.AddressLabel: "example.com:8080", diff --git a/web/api/v2/api.go b/web/api/v2/api.go index 79c73831b3..ff97661d94 100644 --- a/web/api/v2/api.go +++ b/web/api/v2/api.go @@ -40,7 +40,7 @@ import ( "github.com/prometheus/prometheus/pkg/timestamp" pb "github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/promql" - "github.com/prometheus/prometheus/retrieval" + "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage" ) @@ -50,7 +50,7 @@ type API struct { now func() time.Time db func() *tsdb.DB q func(ctx context.Context, mint, maxt int64) (storage.Querier, error) - targets func() []*retrieval.Target + targets func() []*scrape.Target alertmanagers func() []*url.URL } @@ -60,7 +60,7 @@ func New( db func() *tsdb.DB, qe *promql.Engine, q func(ctx context.Context, mint, maxt int64) (storage.Querier, error), - targets func() []*retrieval.Target, + targets func() []*scrape.Target, alertmanagers func() []*url.URL, enableAdmin bool, ) *API { diff --git a/web/web.go b/web/web.go index 5271db67e5..0a4ee75000 100644 --- a/web/web.go +++ b/web/web.go @@ -55,8 +55,8 @@ import ( "github.com/prometheus/prometheus/notifier" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/promql" - "github.com/prometheus/prometheus/retrieval" "github.com/prometheus/prometheus/rules" + "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/template" "github.com/prometheus/prometheus/util/httputil" @@ -71,7 +71,7 @@ var localhostRepresentations = []string{"127.0.0.1", "localhost"} type Handler struct { logger log.Logger - scrapeManager *retrieval.ScrapeManager + scrapeManager *scrape.ScrapeManager ruleManager *rules.Manager queryEngine *promql.Engine context context.Context @@ -125,7 +125,7 @@ type Options struct { TSDB func() *tsdb.DB Storage storage.Storage QueryEngine *promql.Engine - ScrapeManager *retrieval.ScrapeManager + ScrapeManager *scrape.ScrapeManager RuleManager *rules.Manager Notifier *notifier.Manager Version *PrometheusVersion @@ -404,7 +404,7 @@ func (h *Handler) Run(ctx context.Context) error { h.options.TSDB, h.options.QueryEngine, h.options.Storage.Querier, - func() []*retrieval.Target { + func() []*scrape.Target { return h.options.ScrapeManager.Targets() }, func() []*url.URL { @@ -594,7 +594,7 @@ func (h *Handler) serviceDiscovery(w http.ResponseWriter, r *http.Request) { sort.Strings(index) scrapeConfigData := struct { Index []string - Targets map[string][]*retrieval.Target + Targets map[string][]*scrape.Target }{ Index: index, Targets: targets, @@ -604,7 +604,7 @@ func (h *Handler) serviceDiscovery(w http.ResponseWriter, r *http.Request) { func (h *Handler) targets(w http.ResponseWriter, r *http.Request) { // Bucket targets by job label - tps := map[string][]*retrieval.Target{} + tps := map[string][]*scrape.Target{} for _, t := range h.scrapeManager.Targets() { job := t.Labels().Get(model.JobLabel) tps[job] = append(tps[job], t) @@ -617,7 +617,7 @@ func (h *Handler) targets(w http.ResponseWriter, r *http.Request) { } h.executeTemplate(w, "targets.html", struct { - TargetPools map[string][]*retrieval.Target + TargetPools map[string][]*scrape.Target }{ TargetPools: tps, }) @@ -707,21 +707,21 @@ func tmplFuncs(consolesPath string, opts *Options) template_text.FuncMap { } return u }, - "numHealthy": func(pool []*retrieval.Target) int { + "numHealthy": func(pool []*scrape.Target) int { alive := len(pool) for _, p := range pool { - if p.Health() != retrieval.HealthGood { + if p.Health() != scrape.HealthGood { alive-- } } return alive }, - "healthToClass": func(th retrieval.TargetHealth) string { + "healthToClass": func(th scrape.TargetHealth) string { switch th { - case retrieval.HealthUnknown: + case scrape.HealthUnknown: return "warning" - case retrieval.HealthGood: + case scrape.HealthGood: return "success" default: return "danger" From 6ce84dbcb1dca44c576895612726b1c3de80122b Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Thu, 1 Feb 2018 10:06:24 +0000 Subject: [PATCH 2/2] rename ScrapeManager struct to Manager to remove stutter --- scrape/manager.go | 22 +++++++++++----------- web/web.go | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/scrape/manager.go b/scrape/manager.go index 356f1d8627..b498ea0b40 100644 --- a/scrape/manager.go +++ b/scrape/manager.go @@ -31,10 +31,10 @@ type Appendable interface { Appender() (storage.Appender, error) } -// NewManager is the ScrapeManager constructor -func NewManager(logger log.Logger, app Appendable) *ScrapeManager { +// NewManager is the Manager constructor +func NewManager(logger log.Logger, app Appendable) *Manager { - return &ScrapeManager{ + return &Manager{ append: app, logger: logger, scrapeConfigs: make(map[string]*config.ScrapeConfig), @@ -43,9 +43,9 @@ func NewManager(logger log.Logger, app Appendable) *ScrapeManager { } } -// ScrapeManager maintains a set of scrape pools and manages start/stop cycles +// Manager maintains a set of scrape pools and manages start/stop cycles // when receiving new target groups form the discovery manager. -type ScrapeManager struct { +type Manager struct { logger log.Logger append Appendable scrapeConfigs map[string]*config.ScrapeConfig @@ -55,7 +55,7 @@ type ScrapeManager struct { } // Run starts background processing to handle target updates and reload the scraping loops. -func (m *ScrapeManager) Run(tsets <-chan map[string][]*targetgroup.Group) error { +func (m *Manager) Run(tsets <-chan map[string][]*targetgroup.Group) error { for { select { case ts := <-tsets: @@ -67,7 +67,7 @@ func (m *ScrapeManager) Run(tsets <-chan map[string][]*targetgroup.Group) error } // Stop cancels all running scrape pools and blocks until all have exited. -func (m *ScrapeManager) Stop() { +func (m *Manager) Stop() { for _, sp := range m.scrapePools { sp.stop() } @@ -75,7 +75,7 @@ func (m *ScrapeManager) Stop() { } // ApplyConfig resets the manager's target providers and job configurations as defined by the new cfg. -func (m *ScrapeManager) ApplyConfig(cfg *config.Config) error { +func (m *Manager) ApplyConfig(cfg *config.Config) error { m.mtx.Lock() defer m.mtx.Unlock() c := make(map[string]*config.ScrapeConfig) @@ -98,7 +98,7 @@ func (m *ScrapeManager) ApplyConfig(cfg *config.Config) error { } // TargetMap returns map of active and dropped targets and their corresponding scrape config job name. -func (m *ScrapeManager) TargetMap() map[string][]*Target { +func (m *Manager) TargetMap() map[string][]*Target { m.mtx.Lock() defer m.mtx.Unlock() @@ -116,7 +116,7 @@ func (m *ScrapeManager) TargetMap() map[string][]*Target { } // Targets returns the targets currently being scraped. -func (m *ScrapeManager) Targets() []*Target { +func (m *Manager) Targets() []*Target { m.mtx.Lock() defer m.mtx.Unlock() @@ -132,7 +132,7 @@ func (m *ScrapeManager) Targets() []*Target { return targets } -func (m *ScrapeManager) reload(t map[string][]*targetgroup.Group) { +func (m *Manager) reload(t map[string][]*targetgroup.Group) { for tsetName, tgroup := range t { scrapeConfig, ok := m.scrapeConfigs[tsetName] if !ok { diff --git a/web/web.go b/web/web.go index 0a4ee75000..e162cc1b35 100644 --- a/web/web.go +++ b/web/web.go @@ -71,7 +71,7 @@ var localhostRepresentations = []string{"127.0.0.1", "localhost"} type Handler struct { logger log.Logger - scrapeManager *scrape.ScrapeManager + scrapeManager *scrape.Manager ruleManager *rules.Manager queryEngine *promql.Engine context context.Context @@ -125,7 +125,7 @@ type Options struct { TSDB func() *tsdb.DB Storage storage.Storage QueryEngine *promql.Engine - ScrapeManager *scrape.ScrapeManager + ScrapeManager *scrape.Manager RuleManager *rules.Manager Notifier *notifier.Manager Version *PrometheusVersion