MODULES: Add maxbuckets to the kibana config json (#7451)

* Add maxbuckets to the kibana config json

* change METRICS_MAX_BUCKETS to 86400 and fix specs
This commit is contained in:
Guy Boertje 2017-06-15 17:56:02 +01:00 committed by GitHub
parent 448bda167f
commit 1c47ab0f9b
2 changed files with 13 additions and 10 deletions

View file

@ -10,7 +10,8 @@ module LogStash module Modules class KibanaConfig
include LogStash::Util::Loggable
ALLOWED_DIRECTORIES = ["search", "visualization"]
METRICS_MAX_BUCKETS = (24 * 60 * 60).freeze # 24 hours of events/sec buckets.
KIBANA_CONFIG_CONTENT_ID = "5.5.0".freeze
attr_reader :index_name
# We name it `modul` here because `module` has meaning in Ruby.
@ -18,7 +19,7 @@ module LogStash module Modules class KibanaConfig
@directory = ::File.join(modul.directory, "kibana")
@name = modul.module_name
@settings = settings
@index_name = settings.fetch("dashboards.kibana_index", ".kibana")
@index_name = @settings.fetch("dashboards.kibana_index", ".kibana")
end
def dashboards
@ -29,18 +30,19 @@ module LogStash module Modules class KibanaConfig
end
end
def index_pattern
def kibana_config_patches
pattern_name = "#{@name}-*"
default_index_json = '{"defaultIndex": "#{pattern_name}"}'
default_index_content_id = @settings.fetch("index_pattern.kibana_version", "5.4.0") # make this 5.5.0
metrics_max_buckets = @settings.fetch("dashboards.metrics_max_buckets", METRICS_MAX_BUCKETS).to_s
kibana_config_json = '{"defaultIndex": "' + pattern_name + '}", "metrics:max_buckets": "' + metrics_max_buckets + '"}'
kibana_config_content_id = @settings.fetch("index_pattern.kibana_version", KIBANA_CONFIG_CONTENT_ID)
[
KibanaResource.new(@index_name, "index-pattern", dynamic("index-pattern"),nil, pattern_name),
KibanaResource.new(@index_name, "config", nil, default_index_json, default_index_content_id)
KibanaResource.new(@index_name, "config", nil, kibana_config_json, kibana_config_content_id)
]
end
def resources
list = index_pattern
list = kibana_config_patches
dashboards.each do |board|
extract_panels_into(board, list)
end

View file

@ -1,6 +1,7 @@
# encoding: utf-8
#
require "logstash/namespace"
require "logstash/modules/kibana_config"
require "logstash/modules/scaffold"
require "logstash/modules/importer"
require "logstash/elasticsearch_client"
@ -113,8 +114,8 @@ ERB
expect(files[0].content_path).to eq("gem-home/kibana/index-pattern/foo.json")
expect(files[0].import_path).to eq(".kibana/index-pattern/foo-*")
expect(files[1].content).to eq("{\"defaultIndex\": \"\#{pattern_name}\"}")
expect(files[1].import_path).to eq(".kibana/config/5.4.0")
expect(files[1].content).to eq("{\"defaultIndex\": \"foo-*}\", \"metrics:max_buckets\": \"#{LogStash::Modules::KibanaConfig::METRICS_MAX_BUCKETS}\"}")
expect(files[1].import_path).to eq(".kibana/config/#{LogStash::Modules::KibanaConfig::KIBANA_CONFIG_CONTENT_ID}")
expect(files[2].content_path).to eq("gem-home/kibana/dashboard/Foo-Dashboard.json")
expect(files[2].import_path).to eq(".kibana/dashboard/Foo-Dashboard")
@ -145,7 +146,7 @@ ERB
[
"_template/cef",
".kibana/index-pattern/cef-*",
".kibana/config/5.4.0",
".kibana/config/#{LogStash::Modules::KibanaConfig::KIBANA_CONFIG_CONTENT_ID}",
".kibana/dashboard/FW-Dashboard",
".kibana/visualization/FW-Metrics",
".kibana/visualization/FW-Last-Update",