Skip to content

Commit 37edb69

Browse files
authored
Merge pull request kubernetes#81592 from serathius/stable-metric-analysis-stdin
Pass list of files through stdin to avoid hitting ARG_MAX on some env…
2 parents 46b33af + c62da00 commit 37edb69

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

test/instrumentation/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ genrule(
4444
"//:all-srcs",
4545
],
4646
outs = ["stable-metrics-list.yaml"],
47-
cmd = "./$(locations :instrumentation) $(locations //:all-srcs) > $@",
47+
cmd = "for loc in $(locations //:all-srcs); do echo $$loc; done | ./$(locations :instrumentation) - > $@",
4848
message = "Listing all stable metrics.",
4949
tools = [":instrumentation"],
5050
)

test/instrumentation/main.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"bufio"
2021
"flag"
2122
"fmt"
2223
"go/ast"
@@ -42,18 +43,34 @@ const (
4243
func main() {
4344
flag.Parse()
4445
if len(flag.Args()) < 1 {
45-
fmt.Fprintf(os.Stderr, "USAGE: %s <DIR or FILE> [...]\n", os.Args[0])
46+
fmt.Fprintf(os.Stderr, "USAGE: %s <DIR or FILE or '-'> [...]\n", os.Args[0])
4647
os.Exit(64)
4748
}
4849

4950
stableMetrics := []metric{}
5051
errors := []error{}
5152

53+
addStdin := false
5254
for _, arg := range flag.Args() {
55+
if arg == "-" {
56+
addStdin = true
57+
continue
58+
}
5359
ms, es := searchPathForStableMetrics(arg)
5460
stableMetrics = append(stableMetrics, ms...)
5561
errors = append(errors, es...)
5662
}
63+
if addStdin {
64+
scanner := bufio.NewScanner(os.Stdin)
65+
scanner.Split(bufio.ScanLines)
66+
for scanner.Scan() {
67+
arg := scanner.Text()
68+
ms, es := searchPathForStableMetrics(arg)
69+
stableMetrics = append(stableMetrics, ms...)
70+
errors = append(errors, es...)
71+
}
72+
}
73+
5774
for _, err := range errors {
5875
fmt.Fprintf(os.Stderr, "%s\n", err)
5976
}

0 commit comments

Comments
 (0)