Module: LogStash::Outputs::ElasticSearch::Ilm

Included in:
LogStash::Outputs::ElasticSearch
Defined in:
lib/logstash/outputs/elasticsearch/ilm.rb

Constant Summary collapse

ILM_POLICY_PATH =
"default-ilm-policy.json"

Instance Method Summary collapse

Instance Method Details

#default_rollover_alias?(rollover_alias) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/logstash/outputs/elasticsearch/ilm.rb', line 14

def default_rollover_alias?(rollover_alias)
  rollover_alias == LogStash::Outputs::ElasticSearch::DEFAULT_ROLLOVER_ALIAS
end

#ilm_alias_set?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/logstash/outputs/elasticsearch/ilm.rb', line 18

def ilm_alias_set?
  default_index?(@index) || !default_rollover_alias?(@ilm_rollover_alias)
end

#ilm_in_use?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/logstash/outputs/elasticsearch/ilm.rb', line 22

def ilm_in_use?
  return @ilm_actually_enabled if defined?(@ilm_actually_enabled)
  @ilm_actually_enabled =
    begin
      if @ilm_enabled == 'auto'
        if ilm_on_by_default?
          ilm_ready, error = ilm_ready?
          if !ilm_ready
            @logger.info("Index Lifecycle Management is set to 'auto', but will be disabled - #{error}")
            false
          else
            ilm_alias_set?
          end
        else
          @logger.info("Index Lifecycle Management is set to 'auto', but will be disabled - Your Elasticsearch cluster is before 7.0.0, which is the minimum version required to automatically run Index Lifecycle Management")
          false
        end
      elsif @ilm_enabled.to_s == 'true'
        ilm_ready, error = ilm_ready?
        raise LogStash::ConfigurationError,"Index Lifecycle Management is set to enabled in Logstash, but cannot be used - #{error}"  unless ilm_ready
        ilm_alias_set?
      else
        false
      end
    end
end

#ilm_on_by_default?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/logstash/outputs/elasticsearch/ilm.rb', line 49

def ilm_on_by_default?
  maximum_seen_major_version >= 7
end

#ilm_ready?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/logstash/outputs/elasticsearch/ilm.rb', line 53

def ilm_ready?
  # Check the Elasticsearch instance for ILM readiness - this means that the version has to be a non-OSS release, with ILM feature
  # available and enabled.
  begin
    xpack = client.get_xpack_info
    features = xpack.nil? || xpack.empty? ? nil : xpack["features"]
    ilm = features.nil? ? nil : features["ilm"]
    return false, "Index Lifecycle management is not installed on your Elasticsearch cluster" if features.nil? || ilm.nil?
    return false, "Index Lifecycle management is not available in your Elasticsearch cluster" unless ilm['available']
    return false, "Index Lifecycle management is not enabled in your Elasticsearch cluster" unless ilm['enabled']
    return true, nil
  rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
    # Check xpack endpoint: If no xpack endpoint, then this version of Elasticsearch is not compatible
    if e.response_code == 404
      return false, "Index Lifecycle management is not installed on your Elasticsearch cluster"
    elsif e.response_code == 400
      return false, "Index Lifecycle management is not installed on your Elasticsearch cluster"
    else
      raise e
    end
  end
end

#setup_ilmObject



6
7
8
9
10
11
12
# File 'lib/logstash/outputs/elasticsearch/ilm.rb', line 6

def setup_ilm
  return unless ilm_in_use?
    logger.warn("Overwriting supplied index #{@index} with rollover alias #{@ilm_rollover_alias}") unless default_index?(@index)
    @index = @ilm_rollover_alias
    maybe_create_rollover_alias
    maybe_create_ilm_policy
end