Search function in setup menu says "Currently indexing, please try again shortly."

CMK version: 2.1.0p38
OS version: SLES15.4 and Ubuntu 22

Error message: Currently indexing, please try again shortly.

Output of “cmk --debug -vvn hostname”: n/a

I write lots of own plugins and recently I switched to the function _l() instead of _() for translation purposes because that seems the new (since 2.x) way to go for strings that are to be translated.

I use the _l() function in my metrics and WATO plugins.

Since that time every now and then the search function in the setup menu ceases working and shows “Currently indexing, please try again shortly.” instead:

image

In ~/var/log/web.log the following exception about an unexpected LazyString appears:

2024-02-27 10:42:59,712 [40] [cmk.web.background-job 224677] Exception in background function
Traceback (most recent call last):
  File "/omd/sites/testsite/lib/python3/cmk/gui/background_job.py", line 246, in _execute_function
    func_ptr(*args, **kwargs)
  File "/omd/sites/testsite/lib/python3/cmk/gui/watolib/search.py", line 496, in _build_index_background
    IndexBuilder(match_item_generator_registry).build_full_index()
  File "/omd/sites/testsite/lib/python3/cmk/gui/watolib/search.py", line 244, in build_full_index
    self._build_index(self._registry.values())
  File "/omd/sites/testsite/lib/python3/cmk/gui/watolib/search.py", line 129, in _build_index
    self._do_build_index(match_item_generators)
  File "/omd/sites/testsite/lib/python3/cmk/gui/watolib/search.py", line 156, in _do_build_index
    pipeline.execute()
  File "/omd/sites/testsite/lib/python3.9/site-packages/redis/client.py", line 2120, in execute
    return conn.retry.call_with_retry(
  File "/omd/sites/testsite/lib/python3.9/site-packages/redis/retry.py", line 46, in call_with_retry
    return do()
  File "/omd/sites/testsite/lib/python3.9/site-packages/redis/client.py", line 2121, in <lambda>
    lambda: execute(conn, stack, raise_on_error),
  File "/omd/sites/testsite/lib/python3.9/site-packages/redis/client.py", line 1964, in _execute_transaction
    all_cmds = connection.pack_commands(
  File "/omd/sites/testsite/lib/python3.9/site-packages/redis/connection.py", line 920, in pack_commands
    for chunk in self._command_packer.pack(*cmd):
  File "/omd/sites/testsite/lib/python3.9/site-packages/redis/connection.py", line 560, in pack
    for arg in map(self.encode, args):
  File "/omd/sites/testsite/lib/python3.9/site-packages/redis/connection.py", line 116, in encode
    raise DataError(
redis.exceptions.DataError: Invalid input of type: 'LazyString'. Convert to a bytes, string, int or float first.

I tried to increase the loglevel but that didn’t help. Maybe I picked the wrong loglevel or debug setting because there are so many of them.

The other posts here (e.g. Search Index in Setup is not working) didn’t help either because they say it was a broken MKP and the exception is a different one.

Strange thing is: if I switch back to an older version of my MKP (without the _l() function) and then again switch back to my latest MKP (with _l()), then the search function works again.

Is this a known problem?

Apparently the _l() function must not be used in WATO plugins.

When I changed the calls to the _l() function in my WATO plugins back to the old _() function, then the search function again works.

This is strange and I’ll continue to keep an eye on this.

1 Like

Hey @Dirk!
Thanks for reporting.
We are already looking into this and whether we can fix it on our end.
But it sounds like you already have a workaround, or an understanding, of what to do?

1 Like

Hey @robin.gierse , thanks for coming back to this.

Well, the exception about the unexpected LazyString appeared when I used the search bar in the setup menu. And the new function _l() returns such a LazyString.

I then wondered which of my code uses the _l() function AND can be searched for in the setup menu. The check plugins neither use _() nor _l(). My Metric plugins previously used _() and now some of them use _l() but the search bar doesn’t care about them. You cannot search for metrics (I think).

But the WATO plugins: the search bar finds them so it must somehow be iterating their titles (at least) and as soon as I switched back from _l() to _(), thus avoiding the LazyString, the exception vanished.

So my workaraound is to avoid _l() in WATO plugins and use the “classic” _() instead.

1 Like

Thanks for the feedback! I’ll make sure to pass it on. :+1:

1 Like

I got an update from the development team (auto-translated):

The problem is related to the localization of the strings. “_l(…)” is only localized later and currently there are problems when the search index of our Redis instance is to be built based on these not-yet-strings. This happens for all MKPs that appear there later, specifically Wato plugins.

Fixing the problem is quite time-consuming and involves some modifications that we do not want to port to stable versions.

In 2.3, the problem has already been solved by the introduction of the new plugin APIs. There, neither _l(…) nor _(…) will be used in the MKPs, and the parts of the API such as “Title” etc. will be localized correctly and then passed on to Redis.

Until then, we recommend the use of “_(…)” in plugins.

1 Like