All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.graylog2.indexer.searches.SearchesClusterConfig Maven / Gradle / Ivy

There is a newer version: 6.1.4
Show newest version
/*
 * 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
 * .
 */
package org.graylog2.indexer.searches;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.graylog.autovalue.WithBeanGetter;
import org.graylog2.indexer.searches.timerangepresets.TimerangePreset;
import org.graylog2.plugin.Message;
import org.joda.time.Period;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Set;

@JsonAutoDetect
@AutoValue
@WithBeanGetter
public abstract class SearchesClusterConfig {
    private static final Period DEFAULT_QUERY_TIME_RANGE_LIMIT = Period.ZERO;
    private static final Map DEFAULT_RELATIVE_TIMERANGE_OPTIONS = ImmutableMap.builder()
            .put(Period.minutes(5), "5 minutes")
            .put(Period.minutes(15), "15 minutes")
            .put(Period.minutes(30), "30 minutes")
            .put(Period.hours(1), "1 hour")
            .put(Period.hours(2), "2 hours")
            .put(Period.hours(8), "8 hours")
            .put(Period.days(1), "1 day")
            .put(Period.days(2), "2 days")
            .put(Period.days(5), "5 days")
            .put(Period.days(7), "7 days")
            .put(Period.days(14), "14 days")
            .put(Period.days(30), "30 days")
            .put(Period.ZERO, "all messages")
            .build();
    private static final Map DEFAULT_SURROUNDING_TIMERANGE_OPTIONS = ImmutableMap.builder()
            .put(Period.seconds(1), "1 second")
            .put(Period.seconds(5), "5 seconds")
            .put(Period.seconds(10), "10 seconds")
            .put(Period.seconds(30), "30 seconds")
            .put(Period.minutes(1), "1 minute")
            .put(Period.minutes(5), "5 minutes")
            .build();
    private static final Set DEFAULT_SURROUNDING_FILTER_FIELDS = ImmutableSet.builder()
            .add("source")
            .add(Message.FIELD_GL2_SOURCE_INPUT)
            .add("file")
            .add("source_file")
            .build();
    private static final Set DEFAULT_ANALYSIS_DISABLED_FIELDS = ImmutableSet.builder()
            .add("message")
            .add("full_message")
            .build();

    private static final Map DEFAULT_AUTO_REFRESH_TIMERANGE_OPTIONS = ImmutableMap.builder()
            .put(Period.seconds(1), "1 second")
            .put(Period.seconds(2), "2 second")
            .put(Period.seconds(5), "5 seconds")
            .put(Period.seconds(10), "10 seconds")
            .put(Period.seconds(30), "30 seconds")
            .put(Period.minutes(1), "1 minute")
            .put(Period.minutes(5), "5 minutes")
            .build();

    private static final Period DEFAULT_AUTO_REFRESH_DEFAULT_OPTION = Period.seconds(5);

    @JsonProperty("quick_access_timerange_presets")
    public abstract List quickAccessTimerangePresets();

    @JsonProperty("query_time_range_limit")
    public abstract Period queryTimeRangeLimit();

    @JsonProperty("relative_timerange_options")
    public abstract Map relativeTimerangeOptions();

    @JsonProperty("surrounding_timerange_options")
    public abstract Map surroundingTimerangeOptions();

    @JsonProperty("surrounding_filter_fields")
    public abstract Set surroundingFilterFields();

    @JsonProperty("analysis_disabled_fields")
    public abstract Set analysisDisabledFields();

    @JsonProperty("auto_refresh_timerange_options")
    public abstract Map autoRefreshTimerangeOptions();

    @JsonProperty("default_auto_refresh_option")
    public abstract Period defaultAutoRefreshOption();

    @JsonCreator
    public static SearchesClusterConfig create(@JsonProperty("query_time_range_limit") Period queryTimeRangeLimit,
                                               @JsonProperty("relative_timerange_options") Map relativeTimerangeOptions,
                                               @JsonProperty("surrounding_timerange_options") Map surroundingTimerangeOptions,
                                               @JsonProperty("surrounding_filter_fields") Set surroundingFilterFields,
                                               @JsonProperty("analysis_disabled_fields") @Nullable Set analysisDisabledFields,
                                               @JsonProperty("auto_refresh_timerange_options") @Nullable Map autoRefreshTimerangeOptions,
                                               @JsonProperty("default_auto_refresh_option") Period defaultAutoRefreshOption,
                                               @JsonProperty("quick_access_timerange_presets") @Nullable List quickAccessTimerangePresets
    ) {
        return builder()
                .quickAccessTimerangePresets(quickAccessTimerangePresets == null ? List.of() : quickAccessTimerangePresets)
                .queryTimeRangeLimit(queryTimeRangeLimit)
                .relativeTimerangeOptions(relativeTimerangeOptions)
                .surroundingTimerangeOptions(surroundingTimerangeOptions)
                .surroundingFilterFields(surroundingFilterFields)
                .analysisDisabledFields(analysisDisabledFields == null ? DEFAULT_ANALYSIS_DISABLED_FIELDS : analysisDisabledFields)
                .autoRefreshTimerangeOptions(autoRefreshTimerangeOptions == null ? DEFAULT_AUTO_REFRESH_TIMERANGE_OPTIONS : autoRefreshTimerangeOptions)
                .defaultAutoRefreshOption(defaultAutoRefreshOption == null ? DEFAULT_AUTO_REFRESH_DEFAULT_OPTION : defaultAutoRefreshOption)
                .build();
    }

    public static SearchesClusterConfig createDefault() {
        return builder()
                .queryTimeRangeLimit(DEFAULT_QUERY_TIME_RANGE_LIMIT)
                .relativeTimerangeOptions(DEFAULT_RELATIVE_TIMERANGE_OPTIONS)
                .surroundingTimerangeOptions(DEFAULT_SURROUNDING_TIMERANGE_OPTIONS)
                .surroundingFilterFields(DEFAULT_SURROUNDING_FILTER_FIELDS)
                .analysisDisabledFields(DEFAULT_ANALYSIS_DISABLED_FIELDS)
                .autoRefreshTimerangeOptions(DEFAULT_AUTO_REFRESH_TIMERANGE_OPTIONS)
                .defaultAutoRefreshOption(DEFAULT_AUTO_REFRESH_DEFAULT_OPTION)
                .quickAccessTimerangePresets(List.of())
                .build();
    }

    public static Builder builder() {
        return new AutoValue_SearchesClusterConfig.Builder();
    }

    public abstract Builder toBuilder();

    @AutoValue.Builder
    public static abstract class Builder {
        public abstract Builder quickAccessTimerangePresets(List quickAccessTimerangePresets);

        public abstract Builder queryTimeRangeLimit(Period queryTimeRangeLimit);

        public abstract Builder relativeTimerangeOptions(Map relativeTimerangeOptions);

        public abstract Builder surroundingTimerangeOptions(Map surroundingTimerangeOptions);

        public abstract Builder surroundingFilterFields(Set surroundingFilterFields);

        public abstract Builder analysisDisabledFields(Set analysisDisabledFields);

        public abstract Builder autoRefreshTimerangeOptions(Map autoRefreshTimerangeOptions);

        public abstract Builder defaultAutoRefreshOption(Period defaultAutoRefreshOption);

        public abstract SearchesClusterConfig build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy