Skip to content

Commit 0cf1f52

Browse files
authored
NETOBSERV-292 End time for time range is now inclusive (#162)
* NETOBSERV-292 End time for time range is now inclusive * Fix tests
1 parent 56a87a0 commit 0cf1f52

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

pkg/handler/flows.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,29 @@ func getStartTime(params url.Values) (string, error) {
6464
}
6565
start = strconv.FormatInt(time.Now().Unix()-r, 10)
6666
}
67+
} else {
68+
// Make sure it is a valid int
69+
_, err := strconv.ParseInt(start, 10, 64)
70+
if err != nil {
71+
return "", errors.New("Could not parse start time: " + err.Error())
72+
}
6773
}
6874
return start, nil
6975
}
7076

77+
// getEndTime will parse end time and ceil it to the next second
78+
func getEndTime(params url.Values) (string, error) {
79+
end := params.Get(endTimeKey)
80+
if len(end) > 0 {
81+
r, err := strconv.ParseInt(end, 10, 64)
82+
if err != nil {
83+
return "", errors.New("Could not parse end time: " + err.Error())
84+
}
85+
end = strconv.Itoa(int(r) + 1)
86+
}
87+
return end, nil
88+
}
89+
7190
// getLimit returns limit as string (used for logQL) and as int (used to check if reached)
7291
func getLimit(params url.Values) (string, int, error) {
7392
limit := params.Get(limitKey)
@@ -111,7 +130,10 @@ func getFlows(cfg loki.Config, client httpclient.Caller, params url.Values) (*mo
111130
if err != nil {
112131
return nil, http.StatusBadRequest, err
113132
}
114-
end := params.Get(endTimeKey)
133+
end, err := getEndTime(params)
134+
if err != nil {
135+
return nil, http.StatusBadRequest, err
136+
}
115137
limit, reqLimit, err := getLimit(params)
116138
if err != nil {
117139
return nil, http.StatusBadRequest, err

pkg/handler/topology.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ func getTopologyFlows(cfg loki.Config, client httpclient.Caller, params url.Valu
4747
if err != nil {
4848
return nil, http.StatusBadRequest, err
4949
}
50-
end := params.Get(endTimeKey)
50+
end, err := getEndTime(params)
51+
if err != nil {
52+
return nil, http.StatusBadRequest, err
53+
}
5154
limit, reqLimit, err := getLimit(params)
5255
if err != nil {
5356
return nil, http.StatusBadRequest, err

pkg/server/server_flows_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ func TestLokiFiltering(t *testing.T) {
104104
outputQueries: []string{`?query={app="netobserv-flowcollector"}&start=1640991600`},
105105
}, {
106106
inputPath: "?endTime=1641160800",
107-
outputQueries: []string{`?query={app="netobserv-flowcollector"}&end=1641160800`},
107+
outputQueries: []string{`?query={app="netobserv-flowcollector"}&end=1641160801`},
108108
}, {
109109
inputPath: "?startTime=1640991600&endTime=1641160800",
110-
outputQueries: []string{`?query={app="netobserv-flowcollector"}&start=1640991600&end=1641160800`},
110+
outputQueries: []string{`?query={app="netobserv-flowcollector"}&start=1640991600&end=1641160801`},
111111
}, {
112112
inputPath: "?timeRange=300000",
113113
outputQueries: []string{`?query={app="netobserv-flowcollector"}&start=${timeNow-300000}`},

web/locales/en/plugin__network-observability-plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"Namespace": "Namespace",
5151
"Owner": "Owner",
5252
"Resource": "Resource",
53+
"From": "From",
54+
"To": "To",
5355
"XL": "XL",
5456
"L": "L",
5557
"M": "M",
@@ -69,8 +71,6 @@
6971
"Cancel": "Cancel",
7072
"At least one column must be selected": "At least one column must be selected",
7173
"Save": "Save",
72-
"From": "From",
73-
"To": "To",
7474
"Export": "Export",
7575
"Following query will be exported as CSV format:": "Following query will be exported as CSV format:",
7676
"Time Range": "Time Range",

web/src/components/modals/time-range-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let displayedFromTime: string | undefined;
3131
let displayedToTime: string | undefined;
3232

3333
export const TimeRangeModal: React.FC<TimeRangeModalProps> = ({ id, isModalOpen, setModalOpen, range, setRange }) => {
34-
const { t } = useTranslation();
34+
const { t } = useTranslation('plugin__network-observability-plugin');
3535
const [error, setError] = React.useState<string | undefined>();
3636
const [fromDate, setFromDate] = React.useState<string | undefined>();
3737
const [fromTime, setFromTime] = React.useState<string | undefined>();

web/src/components/netflow-record/record-panel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export const RecordPanel: React.FC<RecordDrawerProps> = ({
7676
} else {
7777
//Filter at exact same date
7878
const dateSeconds = Math.floor(Number(value) / 1000);
79-
setRange({ from: dateSeconds, to: dateSeconds + 1 });
79+
// Note: "to" field will be rounded up to the next second from the backend
80+
setRange({ from: dateSeconds, to: dateSeconds });
8081
}
8182
},
8283
isDelete: isDelete

0 commit comments

Comments
 (0)