Plugins support (#10495)

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2022-03-29 14:44:39 +02:00 committed by GitHub
parent 83a2e52bc2
commit f9d8e5245a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 224 additions and 3 deletions

View file

@ -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)

View file

@ -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"

View file

@ -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"
)

19
plugins.yml Normal file
View file

@ -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

101
plugins/generate.go Normal file
View file

@ -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)
}
}

19
plugins/minimum.go Normal file
View file

@ -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.
)

75
plugins/plugins.go Normal file
View file

@ -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"
)