Avoid indexing Uuid and EnvVersion fields

These fields compose every Heka message but are useless for end users.
The fix consists in explicitly enumarating fields to be indexed.

Change-Id: I55aa3719dad7d6b300b81aa0409d712f594c2e1e
This commit is contained in:
Swann Croiset 2015-12-24 12:58:21 +01:00
parent ef2d5d8bb4
commit 7b0be2ec8d
5 changed files with 42 additions and 0 deletions

View File

@ -17,10 +17,15 @@ define heka::encoder::es_json (
$es_index_from_timestamp = false, $es_index_from_timestamp = false,
$index = undef, $index = undef,
$ensure = present, $ensure = present,
$fields = undef,
) { ) {
include heka::params include heka::params
if $fields != undef {
validate_array($fields)
}
file { "${config_dir}/encoder-${title}.toml": file { "${config_dir}/encoder-${title}.toml":
ensure => $ensure, ensure => $ensure,
content => template('heka/encoder/es_json.toml.erb'), content => template('heka/encoder/es_json.toml.erb'),

View File

@ -0,0 +1,32 @@
# Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
require 'spec_helper'
describe 'heka::encoder::es_json' do
let(:title) { :es }
let(:facts) do
{:kernel => 'Linux', :operatingsystem => 'Ubuntu',
:osfamily => 'Debian'}
end
describe 'with title = es' do
let(:params) {{:config_dir => '/etc/hekad', :index => 'bar'}}
it { is_expected.to contain_file('/etc/hekad/encoder-es.toml') }
end
describe 'with fields list' do
let(:params) {{:config_dir => '/etc/hekad', :index => 'bar', :fields => ['foo', 'bar']}}
it { is_expected.to contain_file('/etc/hekad/encoder-es.toml').with_content(/fields = \[ "bar", "foo" \]/) }
end
end

View File

@ -2,3 +2,6 @@
type = "ESJsonEncoder" type = "ESJsonEncoder"
index = "<%= @index %>" index = "<%= @index %>"
es_index_from_timestamp = <%= @es_index_from_timestamp %> es_index_from_timestamp = <%= @es_index_from_timestamp %>
<% if @fields -%>
fields = [ <%= @fields.sort.collect{ |x| '"%s"' % x }.join(", ") %> ]
<% end -%>

View File

@ -24,6 +24,7 @@ class lma_collector::elasticsearch (
config_dir => $lma_collector::params::config_dir, config_dir => $lma_collector::params::config_dir,
index => '%{Type}-%{%Y.%m.%d}', index => '%{Type}-%{%Y.%m.%d}',
es_index_from_timestamp => true, es_index_from_timestamp => true,
fields => $lma_collector::params::elasticsearch_fields,
notify => Class['lma_collector::service'], notify => Class['lma_collector::service'],
} }

View File

@ -142,6 +142,7 @@ class lma_collector::params {
$elasticsearch_server = false $elasticsearch_server = false
$elasticsearch_port = '9200' $elasticsearch_port = '9200'
$elasticsearch_fields = ['Timestamp', 'Type', 'Logger', 'Severity', 'Payload', 'Pid', 'Hostname', 'DynamicFields']
$influxdb_server = false $influxdb_server = false
$influxdb_port = '8086' $influxdb_port = '8086'