-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create time range quick access list for multiple time range types (#1…
…5484) * Create QuickAccessTimeRangeForm * Add context for TimeRange Input * Add summary and sortable list. Connect with BE * Replace list. Add button to quick adding to the list * fix title * Adding type definitions. * add filtrated list. Add presets to relative * fix presets to relative * Unify button naming. * Unify positioning of preset value and description on configuration page. * Make sure preset list items do not remount when chaning content. * Remove not needed formik usage. * Fix prop type error. * fix timezone problem on update absoluter timereinge in configuration * Only update presets on configuration page after submitting changes. * fix TimeRangeInput test * Add presets to other tabs * Conversion from timerange options to timerange presets * Migration instead of temporary solution. IDs introduced. All fields of timerange presets required. More detailed information on a reason of failed config save. * ignore time limits when create a new timerange in configuration * fix tsc * fix test * add test to RangePresetDropdown * change icon and submit component in TimeRangeAddToQuickListButton * add test. check show/hide quick access button * Improve accessibility * add test for TimeRangeAddToQuickListButton * Fixing attributes * Fixing attributes * fix issue with ariaLabel * fix test issues * Add QuickAccessTimeRangeForm test * small improvements * small improvements * update telemetry * Add changelog * fix texting when no available presets * refactoring * refactoring * Make quick access time range description required. --------- Co-authored-by: Linus Pahl <[email protected]> Co-authored-by: Lukasz Kaminski <[email protected]>
- Loading branch information
1 parent
68b716f
commit e458db8
Showing
38 changed files
with
1,690 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type = "added" | ||
message = "Create time range quick access list for multiple time range types" | ||
|
||
pulls = ["15484"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...graylog2/indexer/searches/timerangepresets/conversion/PeriodToRelativeRangeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.indexer.searches.timerangepresets.conversion; | ||
|
||
import org.graylog2.plugin.indexer.searches.timeranges.RelativeRange; | ||
import org.joda.time.Period; | ||
|
||
import java.util.function.Function; | ||
|
||
public class PeriodToRelativeRangeConverter implements Function<Period, RelativeRange> { | ||
|
||
@Override | ||
public RelativeRange apply(final Period period) { | ||
if (period != null) { | ||
return RelativeRange.Builder.builder() | ||
.from(period.toStandardSeconds().getSeconds()) | ||
.build(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...er/searches/timerangepresets/conversion/TimerangeOptionsToTimerangePresetsConversion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.indexer.searches.timerangepresets.conversion; | ||
|
||
|
||
import org.graylog2.indexer.searches.timerangepresets.TimerangePreset; | ||
import org.graylog2.plugin.indexer.searches.timeranges.RelativeRange; | ||
import org.joda.time.Period; | ||
|
||
import javax.inject.Inject; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class TimerangeOptionsToTimerangePresetsConversion { | ||
|
||
private final Function<Period, RelativeRange> periodConverter; | ||
|
||
@Inject | ||
public TimerangeOptionsToTimerangePresetsConversion(final PeriodToRelativeRangeConverter periodConverter) { | ||
this.periodConverter = periodConverter; | ||
} | ||
|
||
public List<TimerangePreset> convert(final Map<Period, String> timerangeOptions) { | ||
if (timerangeOptions == null) { | ||
return List.of(); | ||
} | ||
return timerangeOptions.entrySet() | ||
.stream() | ||
.map(entry -> new TimerangePreset( | ||
periodConverter.apply(entry.getKey()), | ||
entry.getValue()) | ||
) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...java/org/graylog2/migrations/V202305221200_MigrateTimerangeOptionsToTimerangePresets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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 | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.migrations; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.google.auto.value.AutoValue; | ||
import org.graylog.autovalue.WithBeanGetter; | ||
import org.graylog2.indexer.searches.SearchesClusterConfig; | ||
import org.graylog2.indexer.searches.timerangepresets.TimerangePreset; | ||
import org.graylog2.indexer.searches.timerangepresets.conversion.TimerangeOptionsToTimerangePresetsConversion; | ||
import org.graylog2.plugin.cluster.ClusterConfigService; | ||
import org.joda.time.Period; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class V202305221200_MigrateTimerangeOptionsToTimerangePresets extends Migration { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(V202305221200_MigrateTimerangeOptionsToTimerangePresets.class); | ||
|
||
private final ClusterConfigService clusterConfigService; | ||
private final TimerangeOptionsToTimerangePresetsConversion conversion; | ||
|
||
@Inject | ||
public V202305221200_MigrateTimerangeOptionsToTimerangePresets(final ClusterConfigService clusterConfigService, | ||
final TimerangeOptionsToTimerangePresetsConversion conversion) { | ||
this.clusterConfigService = clusterConfigService; | ||
this.conversion = conversion; | ||
} | ||
|
||
@Override | ||
public ZonedDateTime createdAt() { | ||
return ZonedDateTime.parse("2023-05-22T12:00:00Z"); | ||
} | ||
|
||
@Override | ||
public void upgrade() { | ||
if (clusterConfigService.get(V202305221200_MigrateTimerangeOptionsToTimerangePresets.MigrationCompleted.class) != null) { | ||
LOG.debug("Migration already completed."); | ||
return; | ||
} | ||
|
||
final SearchesClusterConfig searchesClusterConfig = clusterConfigService.get(SearchesClusterConfig.class); | ||
if (searchesClusterConfig != null) { | ||
final Map<Period, String> relativeTimerangeOptions = searchesClusterConfig.relativeTimerangeOptions(); | ||
if (relativeTimerangeOptions != null && !relativeTimerangeOptions.isEmpty()) { | ||
final List<TimerangePreset> converted = conversion.convert(relativeTimerangeOptions); | ||
List<TimerangePreset> quickAccessTimerangePresets = searchesClusterConfig.quickAccessTimerangePresets(); | ||
List<TimerangePreset> newQuickAccessTimerangePresets = new ArrayList<>(); | ||
if (quickAccessTimerangePresets != null) { | ||
newQuickAccessTimerangePresets.addAll(quickAccessTimerangePresets); | ||
} | ||
newQuickAccessTimerangePresets.addAll(converted); | ||
|
||
final SearchesClusterConfig newConfig = searchesClusterConfig | ||
.toBuilder() | ||
.quickAccessTimerangePresets(newQuickAccessTimerangePresets) | ||
.build(); | ||
clusterConfigService.write(newConfig); | ||
clusterConfigService.write(MigrationCompleted.create()); | ||
LOG.info("Migration created " + relativeTimerangeOptions.size() + " new entries in quickAccessTimerangePresets list, based on relativeTimerangeOptions list"); | ||
return; | ||
} | ||
} | ||
LOG.info("Migration was not needed, no relativeTimerangeOptions data to move"); | ||
} | ||
|
||
@JsonAutoDetect | ||
@AutoValue | ||
@WithBeanGetter | ||
public static abstract class MigrationCompleted { | ||
|
||
@JsonCreator | ||
public static V202305221200_MigrateTimerangeOptionsToTimerangePresets.MigrationCompleted create() { | ||
return new AutoValue_V202305221200_MigrateTimerangeOptionsToTimerangePresets_MigrationCompleted(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...log2/indexer/searches/timerangepresets/conversion/PeriodToRelativeRangeConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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 | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.indexer.searches.timerangepresets.conversion; | ||
|
||
import org.graylog2.plugin.indexer.searches.timeranges.RelativeRange; | ||
import org.joda.time.Period; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
class PeriodToRelativeRangeConverterTest { | ||
|
||
private PeriodToRelativeRangeConverter converter; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
converter = new PeriodToRelativeRangeConverter(); | ||
} | ||
|
||
@Test | ||
void testReturnsNullOnNullInput() { | ||
assertNull(converter.apply(null)); | ||
} | ||
|
||
@Test | ||
void testSecondConversion() { | ||
final RelativeRange result = converter.apply(Period.seconds(5)); | ||
verifyResult(result, 5); | ||
} | ||
|
||
@Test | ||
void testMinuteConversion() { | ||
final RelativeRange result = converter.apply(Period.minutes(30)); | ||
verifyResult(result, 1800); | ||
} | ||
|
||
@Test | ||
void testHourConversion() { | ||
final RelativeRange result = converter.apply(Period.hours(2)); | ||
verifyResult(result, 7200); | ||
} | ||
|
||
@Test | ||
void testDayConversion() { | ||
final RelativeRange result = converter.apply(Period.days(2)); | ||
verifyResult(result, 172800); | ||
} | ||
|
||
@Test | ||
void testMixedPeriodConversion() { | ||
final RelativeRange result = converter.apply(Period.hours(1).plusMinutes(10).plusSeconds(7)); | ||
verifyResult(result, 4207); | ||
} | ||
|
||
private void verifyResult(final RelativeRange result, final int expectedFromField) { | ||
assertThat(result) | ||
.isNotNull() | ||
.satisfies(range -> { | ||
assertThat(range.range()).isEmpty(); | ||
assertThat(range.from()).isPresent().hasValue(expectedFromField); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.