Browse Source

tools/rulechecker: bye bye

pull/854/head
Fabian Reinartz 10 years ago
parent
commit
6e61fd3e96
  1. 14
      Makefile
  2. 26
      tools/Makefile
  3. 1
      tools/rule_checker/.gitignore
  4. 28
      tools/rule_checker/Makefile
  5. 106
      tools/rule_checker/main.go

14
Makefile

@ -26,7 +26,7 @@ advice: $(GOCC)
binary: build binary: build
build: tools $(GOPATH) build: dependencies $(GOPATH)
$(GO) build -o prometheus $(BUILDFLAGS) github.com/prometheus/prometheus/cmd/prometheus $(GO) build -o prometheus $(BUILDFLAGS) github.com/prometheus/prometheus/cmd/prometheus
$(GO) build -o promtool $(BUILDFLAGS) github.com/prometheus/prometheus/cmd/promtool $(GO) build -o promtool $(BUILDFLAGS) github.com/prometheus/prometheus/cmd/promtool
@ -36,7 +36,7 @@ docker: build
tarball: $(ARCHIVE) tarball: $(ARCHIVE)
$(ARCHIVE): build $(ARCHIVE): build
tar -czf $(ARCHIVE) prometheus promtool tools/rule_checker/rule_checker consoles console_libraries tar -czf $(ARCHIVE) prometheus promtool consoles console_libraries
release: REMOTE ?= $(error "can't upload, REMOTE not set") release: REMOTE ?= $(error "can't upload, REMOTE not set")
release: REMOTE_DIR ?= $(error "can't upload, REMOTE_DIR not set") release: REMOTE_DIR ?= $(error "can't upload, REMOTE_DIR not set")
@ -50,12 +50,11 @@ tag:
$(BUILD_PATH)/cache/$(GOPKG): $(BUILD_PATH)/cache/$(GOPKG):
$(CURL) -o $@ -L $(GOURL)/$(GOPKG) $(CURL) -o $@ -L $(GOURL)/$(GOPKG)
benchmark: dependencies tools benchmark: dependencies
$(GO) test $(GO_TEST_FLAGS) -test.run='NONE' -test.bench='.*' -test.benchmem ./... | tee benchmark.txt $(GO) test $(GO_TEST_FLAGS) -test.run='NONE' -test.bench='.*' -test.benchmem ./... | tee benchmark.txt
clean: clean:
$(MAKE) -C $(BUILD_PATH) clean $(MAKE) -C $(BUILD_PATH) clean
$(MAKE) -C tools clean
rm -rf $(TEST_ARTIFACTS) rm -rf $(TEST_ARTIFACTS)
-rm $(ARCHIVE) -rm $(ARCHIVE)
-find . -type f -name '*~' -exec rm '{}' ';' -find . -type f -name '*~' -exec rm '{}' ';'
@ -85,13 +84,10 @@ race_condition_run: race_condition_binary
search_index: search_index:
godoc -index -write_index -index_files='search_index' godoc -index -write_index -index_files='search_index'
test: dependencies tools test: dependencies
$(GO) test $(GO_TEST_FLAGS) ./... $(GO) test $(GO_TEST_FLAGS) ./...
tools: dependencies
$(MAKE) -C tools
web: dependencies web: dependencies
$(MAKE) -C web $(MAKE) -C web
.PHONY: advice binary build clean dependencies documentation format race_condition_binary race_condition_run release run search_index tag tarball test tools .PHONY: advice binary build clean dependencies documentation format race_condition_binary race_condition_run release run search_index tag tarball test

26
tools/Makefile

@ -1,26 +0,0 @@
# Copyright 2013 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.
all: rule_checker
SUFFIXES:
include ../Makefile.INCLUDE
rule_checker:
$(MAKE) -C rule_checker
clean:
$(MAKE) -C rule_checker clean
.PHONY: clean rule_checker

1
tools/rule_checker/.gitignore vendored

@ -1 +0,0 @@
rule_checker

28
tools/rule_checker/Makefile

@ -1,28 +0,0 @@
# Copyright 2013 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.
MAKE_ARTIFACTS = rule_checker
all: rule_checker
SUFFIXES:
include ../../Makefile.INCLUDE
rule_checker: $(shell find . -iname '*.go')
$(GO) build -o rule_checker .
clean:
rm -rf $(MAKE_ARTIFACTS)
.PHONY: clean

106
tools/rule_checker/main.go

@ -1,106 +0,0 @@
// Copyright 2013 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.
// Rule-Checker allows checking the validity of a Prometheus rule file. It
// prints an error if the specified rule file is invalid, while it prints a
// string representation of the parsed rules otherwise.
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"github.com/prometheus/prometheus/promql"
)
var (
flagset = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
ruleFile = flagset.String("rule-file", "", "The path to the rule file to check. (Deprecated)")
)
// checkRules reads rules from in. Sucessfully read rules
// are printed to out.
func checkRules(filename string, in io.Reader, out io.Writer) error {
content, err := ioutil.ReadAll(in)
if err != nil {
return err
}
rules, err := promql.ParseStmts(string(content))
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, "%s: successfully loaded %d rules:\n", filename, len(rules))
for _, rule := range rules {
fmt.Fprint(out, rule.String())
fmt.Fprint(out, "\n")
}
return nil
}
func usage() {
fmt.Fprintf(os.Stderr, "usage: rule_checker [path ...]\n")
flagset.PrintDefaults()
os.Exit(2)
}
func main() {
flagset.Usage = usage
flagset.Parse(os.Args[1:])
if flagset.NArg() == 0 && *ruleFile == "" {
if err := checkRules("<stdin>", os.Stdin, os.Stdout); err != nil {
fmt.Fprintf(os.Stderr, "error checking standard input: %s\n", err)
os.Exit(1)
}
os.Exit(0)
}
paths := flagset.Args()
if *ruleFile != "" {
paths = []string{*ruleFile}
fmt.Fprint(os.Stderr, "warning: usage of -rule-file is deprecated.\n")
}
failed := false
for _, path := range paths {
switch dir, err := os.Stat(path); {
case err != nil:
fmt.Fprintf(os.Stderr, "%s: error checking path: %s\n", path, err)
os.Exit(2)
case dir.IsDir():
fmt.Fprintf(os.Stderr, "%s: error checking path: directories not allowed\n", path)
os.Exit(2)
default:
f, err := os.Open(path)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: error opening file: %s\n", path, err)
failed = true
} else if err := checkRules(path, f, os.Stdout); err != nil {
fmt.Fprintf(os.Stderr, "%s: error checking rules: %s\n", path, err)
failed = true
}
f.Close()
}
}
if failed {
os.Exit(1)
}
}
Loading…
Cancel
Save