Elasticsearch Returner "trying to serialize a value with no field associated with it"
When using the Elasticsearch returner as the ext_job_cache the minion logs the following error:
2015-02-19 10:43:03,680 [salt.utils.schedule][ERROR ] Unhandled exception running state.highstate
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/utils/schedule.py", line 452, in handle_func
self.returners[ret_str](ret)
File "/usr/lib/python2.7/dist-packages/salt/returners/elasticsearch_return.py", line 124, in returner
body=_get_pickler().flatten(ret),
File "/usr/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 68, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 213, in index
_make_path(index, doc_type, id), params=params, body=body)
File "/usr/lib/python2.7/dist-packages/elasticsearch/transport.py", line 284, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/usr/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 55, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 97, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
RequestError: TransportError(400, u'MapperParsingException[object mapping [return] trying to serialize a value with no field associated with it, current value [The function "state.highstate" is running as PID 32561 and was started at 2015, Feb 19 10:43:03.874881 with jid 20150219104303874881]]')
Version report for the minion:
Salt: 2014.7.1
Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
Jinja2: 2.7.2
M2Crypto: 0.21.1
msgpack-python: 0.3.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.10
ioflo: Not Installed
PyZMQ: 14.0.1
RAET: Not Installed
ZMQ: 4.0.4
Mako: 0.9.1
And here's the versions of the elasticsearch packages I'm running:
$ pip freeze | egrep '(elasticsearch|jsonpickle)'
elasticsearch==1.2.0
jsonpickle==0.6.1
Thanks for this report @clinta. Was this working on previous versions and we have a regression here, or no?
I only recently started using the elasticsearch returner, so I'm not sure. On Feb 20, 2015 5:49 PM, "Nicole Thomas" [email protected] wrote:
Thanks for this report @clinta https://github.com/clinta. Was this working on previous versions and we have a regression here, or no?
— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/20826#issuecomment-75334010.
No problem! Just wondering if this was working before if maybe there has always been a bug here. I'm not too familiar with the elasticsearch returner, but we'll take a look. Of course, if you're able to figure out a fix before we do, we'd gladly accept a pull request!
The error output @clinta posted looks like an async job returning before the job is actually finished. Not sure why it's trying to return to ES at that point.
Confirmed with @jcockhren that all the returns were working with 2014.1.
It seems like the current issue (at least one of the issues) with 2014.7 is that the return formats are different between execution modules and state modules. For example, test.ping returns true, so ElasticSearch will map the return field to a boolean type, which causes it to choke when a state module returns a dictionary for the same field.
Hey all,
The long term solution would be to have consistent return formats between states modules and execution modules. @timoguin and I spoke quickly about spiking a solution for this.
A short term solution could be is to have the mapping expect a dictionary and restructure what's returned from execution modules and state modules to into a dictionary to ensure the mapping is consistently works.
@jcockhren +1
I've started working on the elasticsearch returner to make it more flexible. I'm also adding some features that are similar to what @jcockhren said.
As soon as the updated version is merged into upstream, this issue should be fixed.
#24422 will bring index template/ mapping management support and uses a dedicated index per execution module. This means it should fix the issue reported here.
index templates could look like this:
elasticsearch:
lookup:
index_templates:
salt_defaults:
#ensure: absent
config:
template: salt-*
order: 10
settings:
number_of_shards: 1
mappings:
default:
properties:
'@timestamp':
type: date
format: date_time
success:
type: boolean
retcode:
type: short
minion:
type: string
index: not_analyzed
fun:
type: string
index: not_analyzed
jid:
type: string
index: not_analyzed
salt-test_ping:
#ensure: absent
config:
template: salt-test_ping-*
order: 100
#mappings:
# default:
# properties:
# data:
# type: boolean
salt-status_loadavg:
#ensure: absent
config:
template: salt-status_loadavg-*
order: 100
mappings:
default:
properties:
data:
type: object
include_in_all: True
path: full
dynamic: strict
properties:
1-min:
type: float
5-min:
type: float
15-min:
type: float
If you're lucky you don't even need to create self-defined mappings because the new returner won't use a single index for all execution modules (preventing conflicts described above).
(use https://github.com/bechtoldt/saltstack-elasticsearch-formula for ready-to-use formula to create index templates)
this issue should be fixed by #24422, @clinta can you verify?
We are running into a very similar issue with 2015.8.0:
We get an exception like this in our /var/log/salt/minion log file:
2015-10-05 13:21:35,073 [salt.minion ][ERROR ][7977] Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1095, in _thread_return
)](ret)
File "/usr/lib/python2.7/dist-packages/salt/returners/elasticsearch_return.py", line 112, in returner
ret = __salt__['elasticsearch.document_create'](index=index, doc_type=doc_type_version, body=json.dumps(data))
File "/usr/lib/python2.7/dist-packages/salt/modules/elasticsearch.py", line 187, in document_create
result = es.index(index=index, doc_type=doc_type, body=body) # TODO error handling
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 254, in index
_make_path(index, doc_type, id), params=params, body=body)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 307, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 89, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 105, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
RequestError: TransportError(400, u"RemoteTransportException[[logging05][inet[/172.26.18.92:9300]][indices:data/write/index]]; nested: MapperParsingException[object mapping [data] trying to serialize a value with no field associated with it, current value [No matching sls found for 'asdasd' in env 'base']]; ")
The reason seems to be in the first mapping-creation of the depending index.
When the index is created it creates the mapping regarding to what kind of data it sees first.
So our first run was a successful state.sls call that provided a normal data field.
Later we provoke a failed call with an unknown state.
That was when the pasted error occured.
It looks like in case of an error the data field has a different kind of data type compared to when the state.sls call returns normally.
That is kind of awkward because no errors will be recognized by elasticsearch.
@rall0r I made a workaround for this:
https://github.com/saltstack/salt/blob/2015.8/salt/returners/elasticsearch_return.py#L76
As long as Salt doesn't standardizes the data format, I'd recommend not to push failed jobs into the same index.
#26777 #27643
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.