From f9d8e5245a8d1c49efe2a206360097144f1a3763 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Tue, 29 Mar 2022 14:44:39 +0200 Subject: [PATCH] Plugins support (#10495) Signed-off-by: Julien Pivotto --- Makefile | 9 +++- cmd/prometheus/main.go | 2 +- cmd/promtool/main.go | 2 +- plugins.yml | 19 ++++++++ plugins/generate.go | 101 +++++++++++++++++++++++++++++++++++++++++ plugins/minimum.go | 19 ++++++++ plugins/plugins.go | 75 ++++++++++++++++++++++++++++++ 7 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 plugins.yml create mode 100644 plugins/generate.go create mode 100644 plugins/minimum.go create mode 100644 plugins/plugins.go diff --git a/Makefile b/Makefile index 1bf3fe35b..def1cdcf4 100644 --- a/Makefile +++ b/Makefile @@ -78,8 +78,15 @@ tarball: npm_licenses common-tarball .PHONY: docker docker: npm_licenses common-docker +plugins/plugins.go: plugins.yml plugins/generate.go + @echo ">> creating plugins list" + $(GO) generate -tags plugins ./plugins + +.PHONY: plugins +plugins: plugins/plugins.go + .PHONY: build -build: assets assets-compress common-build +build: assets assets-compress common-build plugins .PHONY: bench_tsdb bench_tsdb: $(PROMU) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index fbdb96109..08564eb0f 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -53,13 +53,13 @@ import ( "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/discovery" - _ "github.com/prometheus/prometheus/discovery/install" // Register service discovery implementations. "github.com/prometheus/prometheus/discovery/legacymanager" "github.com/prometheus/prometheus/discovery/targetgroup" "github.com/prometheus/prometheus/model/exemplar" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/relabel" "github.com/prometheus/prometheus/notifier" + _ "github.com/prometheus/prometheus/plugins" // Register plugins. "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/scrape" diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go index bc1b2928a..dbdc825fe 100644 --- a/cmd/promtool/main.go +++ b/cmd/promtool/main.go @@ -51,12 +51,12 @@ import ( "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/discovery" "github.com/prometheus/prometheus/discovery/file" - _ "github.com/prometheus/prometheus/discovery/install" // Register service discovery implementations. "github.com/prometheus/prometheus/discovery/kubernetes" "github.com/prometheus/prometheus/discovery/targetgroup" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/rulefmt" "github.com/prometheus/prometheus/notifier" + _ "github.com/prometheus/prometheus/plugins" // Register plugins. "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/scrape" ) diff --git a/plugins.yml b/plugins.yml new file mode 100644 index 000000000..498ec22c6 --- /dev/null +++ b/plugins.yml @@ -0,0 +1,19 @@ +- github.com/prometheus/prometheus/discovery/aws +- github.com/prometheus/prometheus/discovery/azure +- github.com/prometheus/prometheus/discovery/consul +- github.com/prometheus/prometheus/discovery/digitalocean +- github.com/prometheus/prometheus/discovery/dns +- github.com/prometheus/prometheus/discovery/eureka +- github.com/prometheus/prometheus/discovery/gce +- github.com/prometheus/prometheus/discovery/hetzner +- github.com/prometheus/prometheus/discovery/kubernetes +- github.com/prometheus/prometheus/discovery/linode +- github.com/prometheus/prometheus/discovery/marathon +- github.com/prometheus/prometheus/discovery/moby +- github.com/prometheus/prometheus/discovery/openstack +- github.com/prometheus/prometheus/discovery/puppetdb +- github.com/prometheus/prometheus/discovery/scaleway +- github.com/prometheus/prometheus/discovery/triton +- github.com/prometheus/prometheus/discovery/uyuni +- github.com/prometheus/prometheus/discovery/xds +- github.com/prometheus/prometheus/discovery/zookeeper diff --git a/plugins/generate.go b/plugins/generate.go new file mode 100644 index 000000000..7054b109b --- /dev/null +++ b/plugins/generate.go @@ -0,0 +1,101 @@ +// Copyright 2022 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build plugins +// +build plugins + +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "path" + "path/filepath" + + "gopkg.in/yaml.v2" +) + +//go:generate go run generate.go + +func main() { + data, err := ioutil.ReadFile(filepath.Join("..", "plugins.yml")) + if err != nil { + log.Fatal(err) + } + + var plugins []string + err = yaml.Unmarshal(data, &plugins) + if err != nil { + log.Fatal(err) + } + + f, err := os.Create("plugins.go") + if err != nil { + log.Fatal(err) + } + defer f.Close() + _, err = f.WriteString(`// Copyright 2022 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This file is generated by "make plugins". + +package plugins + +`) + if err != nil { + log.Fatal(err) + } + + if len(plugins) == 0 { + return + } + + _, err = f.WriteString("import (\n") + if err != nil { + log.Fatal(err) + } + + for i, plugin := range plugins { + _, err = f.WriteString(fmt.Sprintf("\t// Register %s plugin.\n", path.Base(plugin))) + if err != nil { + log.Fatal(err) + } + _, err = f.WriteString(fmt.Sprintf("\t_ \"%s\"\n", plugin)) + if err != nil { + log.Fatal(err) + } + if i < len(plugins)-1 { + _, err = f.WriteString("\n") + if err != nil { + log.Fatal(err) + } + } + } + + _, err = f.WriteString(")\n") + if err != nil { + log.Fatal(err) + } +} diff --git a/plugins/minimum.go b/plugins/minimum.go new file mode 100644 index 000000000..8541de922 --- /dev/null +++ b/plugins/minimum.go @@ -0,0 +1,19 @@ +// Copyright 2022 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package plugins + +import ( + _ "github.com/prometheus/prometheus/discovery/file" // Register file plugin. + _ "github.com/prometheus/prometheus/discovery/http" // Register http plugin. +) diff --git a/plugins/plugins.go b/plugins/plugins.go new file mode 100644 index 000000000..2247f805a --- /dev/null +++ b/plugins/plugins.go @@ -0,0 +1,75 @@ +// Copyright 2022 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This file is generated by "make plugins". + +package plugins + +import ( + // Register aws plugin. + _ "github.com/prometheus/prometheus/discovery/aws" + + // Register azure plugin. + _ "github.com/prometheus/prometheus/discovery/azure" + + // Register consul plugin. + _ "github.com/prometheus/prometheus/discovery/consul" + + // Register digitalocean plugin. + _ "github.com/prometheus/prometheus/discovery/digitalocean" + + // Register dns plugin. + _ "github.com/prometheus/prometheus/discovery/dns" + + // Register eureka plugin. + _ "github.com/prometheus/prometheus/discovery/eureka" + + // Register gce plugin. + _ "github.com/prometheus/prometheus/discovery/gce" + + // Register hetzner plugin. + _ "github.com/prometheus/prometheus/discovery/hetzner" + + // Register kubernetes plugin. + _ "github.com/prometheus/prometheus/discovery/kubernetes" + + // Register linode plugin. + _ "github.com/prometheus/prometheus/discovery/linode" + + // Register marathon plugin. + _ "github.com/prometheus/prometheus/discovery/marathon" + + // Register moby plugin. + _ "github.com/prometheus/prometheus/discovery/moby" + + // Register openstack plugin. + _ "github.com/prometheus/prometheus/discovery/openstack" + + // Register puppetdb plugin. + _ "github.com/prometheus/prometheus/discovery/puppetdb" + + // Register scaleway plugin. + _ "github.com/prometheus/prometheus/discovery/scaleway" + + // Register triton plugin. + _ "github.com/prometheus/prometheus/discovery/triton" + + // Register uyuni plugin. + _ "github.com/prometheus/prometheus/discovery/uyuni" + + // Register xds plugin. + _ "github.com/prometheus/prometheus/discovery/xds" + + // Register zookeeper plugin. + _ "github.com/prometheus/prometheus/discovery/zookeeper" +)