Merge pull request #81592 from serathius/stable-metric-analysis-stdin

Pass list of files through stdin to avoid hitting ARG_MAX on some env…
This commit is contained in:
Kubernetes Prow Robot 2019-10-25 15:37:13 -07:00 committed by GitHub
commit 37edb6984b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -44,7 +44,7 @@ genrule(
"//:all-srcs",
],
outs = ["stable-metrics-list.yaml"],
cmd = "./$(locations :instrumentation) $(locations //:all-srcs) > $@",
cmd = "for loc in $(locations //:all-srcs); do echo $$loc; done | ./$(locations :instrumentation) - > $@",
message = "Listing all stable metrics.",
tools = [":instrumentation"],
)

View File

@ -17,6 +17,7 @@ limitations under the License.
package main
import (
"bufio"
"flag"
"fmt"
"go/ast"
@ -42,18 +43,34 @@ const (
func main() {
flag.Parse()
if len(flag.Args()) < 1 {
fmt.Fprintf(os.Stderr, "USAGE: %s <DIR or FILE> [...]\n", os.Args[0])
fmt.Fprintf(os.Stderr, "USAGE: %s <DIR or FILE or '-'> [...]\n", os.Args[0])
os.Exit(64)
}
stableMetrics := []metric{}
errors := []error{}
addStdin := false
for _, arg := range flag.Args() {
if arg == "-" {
addStdin = true
continue
}
ms, es := searchPathForStableMetrics(arg)
stableMetrics = append(stableMetrics, ms...)
errors = append(errors, es...)
}
if addStdin {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
arg := scanner.Text()
ms, es := searchPathForStableMetrics(arg)
stableMetrics = append(stableMetrics, ms...)
errors = append(errors, es...)
}
}
for _, err := range errors {
fmt.Fprintf(os.Stderr, "%s\n", err)
}