prometheus
99 строк · 2.3 Кб
1// Copyright 2022 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14//go:build plugins
15
16package main
17
18import (
19"fmt"
20"log"
21"os"
22"path"
23"path/filepath"
24
25"gopkg.in/yaml.v2"
26)
27
28//go:generate go run generate.go
29
30func main() {
31data, err := os.ReadFile(filepath.Join("..", "plugins.yml"))
32if err != nil {
33log.Fatal(err)
34}
35
36var plugins []string
37err = yaml.Unmarshal(data, &plugins)
38if err != nil {
39log.Fatal(err)
40}
41
42f, err := os.Create("plugins.go")
43if err != nil {
44log.Fatal(err)
45}
46defer f.Close()
47_, err = f.WriteString(`// Copyright 2022 The Prometheus Authors
48// Licensed under the Apache License, Version 2.0 (the "License");
49// you may not use this file except in compliance with the License.
50// You may obtain a copy of the License at
51//
52// http://www.apache.org/licenses/LICENSE-2.0
53//
54// Unless required by applicable law or agreed to in writing, software
55// distributed under the License is distributed on an "AS IS" BASIS,
56// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57// See the License for the specific language governing permissions and
58// limitations under the License.
59
60// This file is generated by "make plugins".
61
62package plugins
63
64`)
65if err != nil {
66log.Fatal(err)
67}
68
69if len(plugins) == 0 {
70return
71}
72
73_, err = f.WriteString("import (\n")
74if err != nil {
75log.Fatal(err)
76}
77
78for i, plugin := range plugins {
79_, err = f.WriteString(fmt.Sprintf("\t// Register %s plugin.\n", path.Base(plugin)))
80if err != nil {
81log.Fatal(err)
82}
83_, err = f.WriteString(fmt.Sprintf("\t_ \"%s\"\n", plugin))
84if err != nil {
85log.Fatal(err)
86}
87if i < len(plugins)-1 {
88_, err = f.WriteString("\n")
89if err != nil {
90log.Fatal(err)
91}
92}
93}
94
95_, err = f.WriteString(")\n")
96if err != nil {
97log.Fatal(err)
98}
99}
100