Skip to content

Commit a20e03c

Browse files
authored
fix(stats/historical): avoid runtime SIGSEGV (#1169)
* fix(stats/historical): avoid runtime SIGSEGV * refactor(stats/historical): optionally set fields
1 parent 6fc2fc1 commit a20e03c

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

pkg/commands/stats/historical.go

+24-7
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ const statusSuccess = "success"
1717
type HistoricalCommand struct {
1818
argparser.Base
1919

20-
Input fastly.GetStatsInput
20+
by string
2121
formatFlag string
22+
from string
23+
region string
2224
serviceName argparser.OptionalServiceNameID
25+
to string
2326
}
2427

2528
// NewHistoricalCommand is the "stats historical" subcommand.
@@ -41,10 +44,10 @@ func NewHistoricalCommand(parent argparser.Registerer, g *global.Data) *Historic
4144
Dst: &c.serviceName.Value,
4245
})
4346

44-
c.CmdClause.Flag("from", "From time, accepted formats at https://fastly.dev/reference/api/metrics-stats/historical-stats").StringVar(c.Input.From)
45-
c.CmdClause.Flag("to", "To time").StringVar(c.Input.To)
46-
c.CmdClause.Flag("by", "Aggregation period (minute/hour/day)").EnumVar(c.Input.By, "minute", "hour", "day")
47-
c.CmdClause.Flag("region", "Filter by region ('stats regions' to list)").StringVar(c.Input.Region)
47+
c.CmdClause.Flag("from", "From time, accepted formats at https://fastly.dev/reference/api/metrics-stats/historical-stats").StringVar(&c.from)
48+
c.CmdClause.Flag("to", "To time").StringVar(&c.to)
49+
c.CmdClause.Flag("by", "Aggregation period (minute/hour/day)").EnumVar(&c.by, "minute", "hour", "day")
50+
c.CmdClause.Flag("region", "Filter by region ('stats regions' to list)").StringVar(&c.region)
4851

4952
c.CmdClause.Flag("format", "Output format (json)").EnumVar(&c.formatFlag, "json")
5053

@@ -61,10 +64,24 @@ func (c *HistoricalCommand) Exec(_ io.Reader, out io.Writer) error {
6164
argparser.DisplayServiceID(serviceID, flag, source, out)
6265
}
6366

64-
c.Input.Service = fastly.ToPointer(serviceID)
67+
input := fastly.GetStatsInput{
68+
Service: fastly.ToPointer(serviceID),
69+
}
70+
if c.by != "" {
71+
input.By = &c.by
72+
}
73+
if c.from != "" {
74+
input.From = &c.from
75+
}
76+
if c.region != "" {
77+
input.Region = &c.region
78+
}
79+
if c.to != "" {
80+
input.To = &c.to
81+
}
6582

6683
var envelope statsResponse
67-
err = c.Globals.APIClient.GetStatsJSON(&c.Input, &envelope)
84+
err = c.Globals.APIClient.GetStatsJSON(&input, &envelope)
6885
if err != nil {
6986
c.Globals.ErrLog.AddWithContext(err, map[string]any{
7087
"Service ID": serviceID,

0 commit comments

Comments
 (0)