Skip to content

Commit ea6d96c

Browse files
committed
Add function to analyse used labels, and not just used metrics.
Signed-off-by: Tom Wilkie <[email protected]>
1 parent 3048e55 commit ea6d96c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/commands/analyse.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package commands
22

33
import (
4+
"encoding/json"
5+
"os"
6+
7+
log "github.com/sirupsen/logrus"
48
"gopkg.in/alecthomas/kingpin.v2"
59
)
610

@@ -91,4 +95,12 @@ func (cmd *AnalyseCommand) Register(app *kingpin.Application) {
9195
ruleFileAnalyseCmd.Flag("output", "The path for the output file").
9296
Default("metrics-in-ruler.json").
9397
StringVar(&rfCmd.outputFile)
98+
99+
analyseCmd.Command("queries", "Extract the used metrics and labels from queries fed in on stdin.").Action(func(_ *kingpin.ParseContext) error {
100+
metrics, err := processQueries(os.Stdin)
101+
if err != nil {
102+
log.Fatalf("failed to process queries: %v", err)
103+
}
104+
return json.NewEncoder(os.Stdout).Encode(metrics)
105+
})
94106
}

0 commit comments

Comments
 (0)