Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logrotate.get logs warnings "Block" '%s' not present or empty." #53988

Closed
boltronics opened this issue Jul 24, 2019 · 4 comments · Fixed by #56105
Closed

logrotate.get logs warnings "Block" '%s' not present or empty." #53988

boltronics opened this issue Jul 24, 2019 · 4 comments · Fixed by #56105
Assignees
Labels
Bug broken, incorrect, or confusing behavior Confirmed Salt engineer has confirmed bug/feature - often including a MCVE good first issue good for someone new to salt severity-low 4th level, cosemtic problems, work around exists
Milestone

Comments

@boltronics
Copy link
Contributor

boltronics commented Jul 24, 2019

Description of Issue

I have a logrotate state sls file that builds up a logrotate configuration from scratch. In doing this, it seems unavoidable that loud WARNING messages will be presented to the user, leading users to worry that something is wrong.

Setup

logrotate.sls state file:

Install logrotate:
  pkg.installed:
    - name: logrotate

{%- for file,  settings in salt['pillar.get']('logrotate', {}).items() %}
# If a /etc/logrotate.d/<file> with the appropriate section doesn't
# pre-exist, logrotate.set will populate the required entries into
# /etc/logrotate.conf instead.
Create /etc/logrotate.d/{{ settings.name }}:
  file.managed:
    - name: /etc/logrotate.d/{{ settings.name }}
    - user: root
    - group: root
    - mode: '0644'
    - contents: |
        {{ file }} {
        }
    - require:
      - pkg: logrotate

{%- for setting, value in settings['settings'].items() %}
Set {{ setting }} in /etc/logrotate.d/{{ settings.name }}:
  logrotate.set:
    - key: {{ file }}
    - value: {{ setting }}
{%- if value %}
    - setting: {{ value }}
{%- else %}
    # Here we avoid a "SaltInvocationError: Error: /path/to/logs/*
    # includes a dict, and a specific setting inside the dict was not
    # declared" error which seems to be Salt issue #48125.
    - setting: ' '
{%- endif %}
    # logrotate.set always seems to report changes (which by default
    # makes using prereq against it pointless), so this is a hacky
    # work-around.
    - unless: >-
        grep -qE '^\s*{{ setting }}\s*{{ value }}$'
        /etc/logrotate.d/{{ settings.name }}
    - prereq_in:
      - file: Create /etc/logrotate.d/{{ settings.name }}
{%- endfor %}
{%- endfor %}

logrotate.sls pillar file:

logrotate:
  '/myapp/log/file/path/*':
    name: myapp
    settings:
      daily: ''
      rotate: 7
      missingok: ''
      notifempty: ''
      compress: ''
      nocreate: ''

Steps to Reproduce Issue

With the above setup, run:

$ sudo salt-call -l warning state.sls logrotate
[WARNING ] Block '/myapp/log/file/path/*' not present or empty.
[WARNING ] Block '/myapp/log/file/path/*' not present or empty.
[WARNING ] Block '/myapp/log/file/path/*' not present or empty.
[WARNING ] Block '/myapp/log/file/path/*' not present or empty.
[WARNING ] Block '/myapp/log/file/path/*' not present or empty.
[WARNING ] Block '/myapp/log/file/path/*' not present or empty.
...

Versions Report

salt-call --versions-report
Salt Version:
           Salt: 2017.7.8
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.5.3
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.24.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: 1.3.7
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.13 (default, Sep 26 2018, 18:42:22)
   python-gnupg: 0.3.9
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.4.3
            ZMQ: 4.2.1
 
System Versions:
           dist: debian 9.9 
         locale: UTF-8
        machine: x86_64
        release: 4.19.0-5-amd64
         system: Linux
        version: debian 9.9 
 
@boltronics
Copy link
Contributor Author

boltronics commented Jul 24, 2019

Here is where the issue is:
https://github.com/saltstack/salt/blob/v2019.2.0/salt/modules/logrotate.py#L169

It's printed whenever the file is empty, which it will be when building the file up from scratch. As such, a warning is too heavy handed since there is no problem and it's to be expected.

I believe a simple info log would suffice, which can easily be hidden or at least won't confuse the user into thinking something is broken. Please let me know if this would be acceptable.

@dwoz dwoz added Bug broken, incorrect, or confusing behavior Low-Hanging Fruit P4 Priority 4 severity-low 4th level, cosemtic problems, work around exists labels Jul 29, 2019
@dwoz dwoz added this to the Approved milestone Jul 29, 2019
@dwoz
Copy link
Contributor

dwoz commented Jul 29, 2019

@boltronics Thanks for pointing this out, I agree and thing this could probably actually be a debug log.

@stale
Copy link

stale bot commented Jan 8, 2020

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.

@stale stale bot added the stale label Jan 8, 2020
@waynew waynew added the Confirmed Salt engineer has confirmed bug/feature - often including a MCVE label Jan 8, 2020
@stale
Copy link

stale bot commented Jan 8, 2020

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Jan 8, 2020
@sagetherage sagetherage added good first issue good for someone new to salt Magnesium Mg release after Na prior to Al and removed Low-Hanging Fruit labels May 23, 2020
@sagetherage sagetherage removed the P4 Priority 4 label Jun 3, 2020
@sagetherage sagetherage modified the milestones: Approved, Magnesium Jul 29, 2020
@sagetherage sagetherage removed the Magnesium Mg release after Na prior to Al label Oct 8, 2020
@sagetherage sagetherage modified the milestones: Magnesium, Approved Oct 8, 2020
Ch3LL pushed a commit to boltronics/salt that referenced this issue Sep 27, 2022
There is no guarantee that a lookup failure is necessarily a problem,
so presenting a message to this effect as a warning has led to
confusion for some (and annoyance for others). This resolves the issue
by showing the message at the debug level.

Fixes saltstack#53988
garethgreenaway added a commit that referenced this issue Sep 28, 2022
* Avoid warning noise in logrotate.get

There is no guarantee that a lookup failure is necessarily a problem,
so presenting a message to this effect as a warning has led to
confusion for some (and annoyance for others). This resolves the issue
by showing the message at the debug level.

Fixes #53988

* Adding a test for changes to logrotate.get.

* Fix pre-commit and add changelog

Co-authored-by: Gareth J. Greenaway <gareth@saltstack.com>
Co-authored-by: Megan Wilhite <mwilhite@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Confirmed Salt engineer has confirmed bug/feature - often including a MCVE good first issue good for someone new to salt severity-low 4th level, cosemtic problems, work around exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants