signalfx / maestro-ng

Orchestration of Docker-based, multi-host environments
https://signalfx.com
Apache License 2.0
683 stars 83 forks source link

exception while configuring json-file log driver via maestro-ng #153

Closed iangkent closed 9 years ago

iangkent commented 9 years ago

I have read the docs for maestro-ng stating that it supports ability to configure log driver. I tried this out and got exception. If I put the max-file value in quotes it works.

  verbose:
    image: busybox:latest
    instances:
      verbose:
        ship: machine
        command: /bin/sh -c "while true; do echo fake log; sleep 1; done"
        limits:
          memory: 10m
        log_driver: json-file
        log_opt:
          max-size: 2K
          max-file: 2

  File "/usr/lib/python2.7/site-packages/maestro/plays/tasks.py", line 145, in _run
    result = self._create_and_start_container()
  File "/usr/lib/python2.7/site-packages/maestro/plays/tasks.py", line 216, in _create_and_start_container
    command=self.container.command)
  File "/usr/lib/python2.7/site-packages/docker/client.py", line 252, in create_container
    return self.create_container_from_config(config, name)
  File "/usr/lib/python2.7/site-packages/docker/client.py", line 263, in create_container_from_config
    return self._result(res, True)
  File "/usr/lib/python2.7/site-packages/docker/clientbase.py", line 119, in _result
    self._raise_for_status(response)
  File "/usr/lib/python2.7/site-packages/docker/clientbase.py", line 115, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
APIError: 500 Server Error: Internal Server Error ("json: cannot unmarshal number into Go value of type string")
mpetazzoni commented 9 years ago

Hmm, can you try with 2k instead of 2K? The values are passed straight through to the Docker Remote API, and the documentation for logging driver options reads:

--log-opt max-size=[0-9+][k|m|g]

And I'm not sure it accepts their uppercase counterparts.

iangkent commented 9 years ago

The problem was not with max-size. The problem is with max-file. I needed to put the number in quotes.

log_opt:
  max-size: 1M
  max-file: '2'
mpetazzoni commented 9 years ago

Yep, I just looked at the Docker daemon code, and it expects a string... which it then promptly converts to an integer: https://github.com/docker/docker/blob/3856c5efa685013b5e82347d5812de4c7788d4ff/daemon/logger/jsonfilelog/jsonfilelog.go#L73

Quite sad that it does not accept an integer, but looking at the way the logging drivers configs are built in Docker it (sort of) makes sense. I'll make a fix to Maestro to make sure that all log_opt key/value pairs are string/string pairs.

petrkalina commented 3 years ago

trying to follow up, but is seems logging config is not effective:

 busybox:
    image: busybox
    instances:
      busybox1:
        ship: test
        log_driver: json-file
        log_opt:
          max-size: 1M
          max-file: '2'
        command:
          - "sh"
          - "-c"
          - "while true; do sleep 0.1; echo `date` - logmessage; done"

however

j4care@dev:/tmp$ docker inspect busybox | grep Log

.. in comparison

j4care@dev:/tmp$ docker run --log-opt max-size=1k --log-opt max-file=2 --rm -d busybox sh -c "while true; do sleep 0.1; echo logmessage; done"
...
j4care@dev:/tmp$ docker inspect youthful_khayyam | grep Log
        "LogPath": "/var/lib/docker/containers/c6937b44f2f79eadfbd7a937c065fc02c0166cd2246fa658fdf6fe5a9f45969a/c6937b44f2f79eadfbd7a937c065fc02c0166cd2246fa658fdf6fe5a9f45969a-json.log",
            "LogConfig": {

what am I doing wrong?