diff --git a/changelog/unreleased/issue-5620.toml b/changelog/unreleased/issue-5620.toml new file mode 100644 index 000000000000..a6c07b50fb73 --- /dev/null +++ b/changelog/unreleased/issue-5620.toml @@ -0,0 +1,5 @@ +type = "c" +message = "Shorten time range of show received messages buttons on inputs, forwarder profiles and sidecars." + +issues = ["5620"] +pulls = ["5621"] diff --git a/graylog2-web-interface/src/components/inputs/InputListItem.jsx b/graylog2-web-interface/src/components/inputs/InputListItem.jsx index e28eb8a2cd8a..891a1c8cf0cb 100644 --- a/graylog2-web-interface/src/components/inputs/InputListItem.jsx +++ b/graylog2-web-interface/src/components/inputs/InputListItem.jsx @@ -27,6 +27,7 @@ import { EntityListItem, IfPermitted, LinkToNode, Spinner } from 'components/com import { ConfigurationWell } from 'components/configurationforms'; import PermissionsMixin from 'util/PermissionsMixin'; import Routes from 'routing/Routes'; +import recentMessagesTimeRange from 'util/TimeRangeHelper'; import { InputForm, InputStateBadge, @@ -116,7 +117,7 @@ const InputListItem = createReactClass({ if (this.isPermitted(this.props.permissions, ['searches:relative'])) { actions.push( + to={Routes.search(`${queryField}:${this.props.input.id}`, recentMessagesTimeRange())}> - + diff --git a/graylog2-web-interface/src/util/TimeRangeHelper.ts b/graylog2-web-interface/src/util/TimeRangeHelper.ts new file mode 100644 index 000000000000..2088e1cebe17 --- /dev/null +++ b/graylog2-web-interface/src/util/TimeRangeHelper.ts @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ + +import type { AbsoluteRangeQueryParameter } from 'views/logic/TimeRange'; + +/** + * Creates an absolute time range that can be used to look up recently received messages. + * It accommodates for the eventuality that messages can have timestamps from the future + * due to wrong timezone parsing or wrong system clocks. + */ +const recentMessagesTimeRange = (): AbsoluteRangeQueryParameter => { + const now = Date.now(); + // The biggest possible time difference on earth is 26 hours. + // It's between Kiribati (UTC+14) and the Howland Islands (UTC-12) + // So we are going to create an absolute range + // from 26 hours in the past to 26 hours into the future. + const fromDate = new Date(now - 26 * 60 * 60000).toISOString(); + const toDate = new Date(now + 26 * 60 * 60000).toISOString(); + + return { rangetype: 'absolute', from: fromDate, to: toDate }; +}; + +export default recentMessagesTimeRange; diff --git a/graylog2-web-interface/src/views/logic/TimeRange.ts b/graylog2-web-interface/src/views/logic/TimeRange.ts index 1b6be9c3dca5..8517be672d5d 100644 --- a/graylog2-web-interface/src/views/logic/TimeRange.ts +++ b/graylog2-web-interface/src/views/logic/TimeRange.ts @@ -31,7 +31,7 @@ type RelativeRangeWithEndQueryParameter = { type RelativeRangeQueryParameter = RelativeRangeStartOnlyQueryParameter | RelativeRangeWithEndQueryParameter; -type AbsoluteRangeQueryParameter = { +export type AbsoluteRangeQueryParameter = { rangetype: 'absolute', from: string, to: string,