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

Logging implementation for tendrl #178

Closed
wants to merge 1 commit into from
Closed

Logging implementation for tendrl #178

wants to merge 1 commit into from

Conversation

GowthamShanmugam
Copy link
Contributor

@GowthamShanmugam GowthamShanmugam commented Jan 24, 2017

tendrl-bug-id: Tendrl/specifications#28
tendrl-spec: logging_implementation

Signed-off-by: GowthamShanmugam gshanmug@redhat.com

self.message.payload["job_id"],
self.message.__dict__,
append=True)
log_message = ("%s:%s") % (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shtripat @brainfunked @r0h4n @nnDarshan @anmolbabu @nthomas-redhat
operation updates are required some sequence key, so we cant use etcdobj save method, and message is an object but is in common so direct write to etcd is used.

@GowthamShanmugam
Copy link
Contributor Author

formatters:
simple:
format: "%(asctime)s - %(filename)s:%(lineno)s - %(funcName)20s() - %(levelname)s - %(message)s"
datefmt: "%Y-%m-%dT%H:%M:%S%z"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have removed format because we cant tell function name and line no and file name from logger , it is passed with message and appended with log message automatically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is it passed with the message? any examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r0h4n
log_message = Message.to_json(log_message)
message = ("%s - %s - %s:%s - %s - %s - %s") % (
self.message.timestamp,
self.message.publisher,
self.message.caller["filename"],
self.message.caller["line_no"],
self.message.caller["function"],
self.message.priority.upper(),
log_message
)

Copy link
Contributor

@brainfunked brainfunked left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r0h4n need you to review.

@@ -40,7 +40,8 @@ For installing node agent following dependencies have to be manually installed:

$ yum install libffi-devel gcc python-devel openssl-devel
$ yum install -y http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
$ yum install hwinfo
$ yum install hwinfo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is hwinfo required for logging implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brainfunked i am not added hwinfo it comes because of some space change i think

log_level: DEBUG
tendrl_message_socket_addr: 127.0.0.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be a UNIX socket, as commented here: https://github.com/Tendrl/node-agent/pull/67/files#r97720923

stream: ext://sys.stdout

info_file_handler:
class: logging.handlers.SysLogHandler
facility: local0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log to local5 or some such. Lots of programmes use local0, local1 etc.

@@ -24,6 +24,7 @@ Requires: collectd
Requires: python-jinja2
Requires: tendrl-commons
Requires: hwinfo
Requires: rsyslog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required.

RECEIVE_DATA_SIZE = 4096


class MessageHandler(gevent.greenlet.Greenlet):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be updated based on Tendrl/commons#134 (comment)

@GowthamShanmugam
Copy link
Contributor Author

@brainfunked @shtripat @nthomas-redhat @anmolbabu @r0h4n @anmolsachan please review this, i have done all the changes

class Logger(object):
def __init__(self, message):
self.message = message
self.etcd_orm = tendrl_ns.etcd_orm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want a copy use the global variable directly tendrl_ns.etcd_orm.....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anmolbabu i will correct it, no need to take copy

def critical(self, message):
LOG.critical(message)

def notice(self, message):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see from line 72, that this func name should match priority I think case wise and also exact name should be the func here. In which case is it NOTIF or notice? Applies to all other funcs above as well. Also if this all that needs to be done is there a better way of doing it? Probably have a map from log levels of tendrl to log levels of logger and use it in getattr directly on LOG object instead of on self? Just a thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will modify those line to call the function easily

def bind_unix_listener(self):
try:
if os.path.exists(PATH):
os.remove(PATH)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need to do this?
I feel just if the socket file is not used currently by some other process it suffices... Please check...
I am not sure though...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anmolbabu i will check it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anmolbabu If we are not removed this file then i will throw exception like "Address already in use". They have to remove manually to run then node agent again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

formatters:
simple:
format: "%(asctime)s - %(filename)s:%(lineno)s - %(funcName)20s() - %(levelname)s - %(message)s"
datefmt: "%Y-%m-%dT%H:%M:%S%z"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is it passed with the message? any examples?



RECEIVE_DATA_SIZE = 4096
PATH = "/etc/tendrl/.node_agent_socket"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to come from configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r0h4n i will change it

@@ -0,0 +1,53 @@
import _socket
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try:
if os.path.exists(PATH):
os.remove(PATH)
self.sock = _socket.socket(_socket.AF_UNIX, _socket.SOCK_STREAM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GowthamShanmugam
Copy link
Contributor Author

@r0h4n message contains one field called caller, it contains all the information about where the message is from and which function and line no. these details are captured using getframeinfo. so there information are appended with message and then logged. so no need log format here. because log format will take the details where the message is logged. Here we are logging the all message in node_agent , so it give wrong function name and line no and file name.

@GowthamShanmugam
Copy link
Contributor Author

@r0h4n example log_message = Message.to_json(log_message)
message = ("%s - %s - %s:%s - %s - %s - %s") % (
self.message.timestamp,
self.message.publisher,
self.message.caller["filename"],
self.message.caller["line_no"],
self.message.caller["function"],
self.message.priority.upper(),
log_message
)

@GowthamShanmugam
Copy link
Contributor Author

@r0h4n all changes are done

@@ -5,3 +5,4 @@ tendrl_ansible_exec_file: $HOME/.tendrl/node-agent/ansible_exec
log_cfg_path: /etc/tendrl/node-agent/node-agent_logging.yaml
log_level: DEBUG
package_source_type: rpm
logging_socket_path: "/etc/tendrl/.node_agent_socket"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this default path is not supposed to be in /etc, application sockets can be store in /tmp/node-agent/.node_agent.sock

help: "Called details"
type: Dict
enabled: true
list: cluster/$TendrlContext.integration_id/messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clusters not cluster

enabled: true
list: cluster/$TendrlContext.integration_id/messages
help: "Cluster Messages"
value: cluster/$TendrlContext.integration_id/messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: clusters

help: "Called details"
type: Dict
enabled: true
list: node/$Node_context.node_id/messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camel case "Messages"

help: "Called details"
type: Dict
enabled: true
list: cluster/$TendrlContext.integration_id/messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelcase "Messages"

help: "Called details"
type: Dict
enabled: true
list: /messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Messages"

@GowthamShanmugam
Copy link
Contributor Author

@r0h4n all changes done

tendrl-spec: logging_implementation

Signed-off-by: GowthamShanmugam <gshanmug@redhat.com>
@GowthamShanmugam
Copy link
Contributor Author

@r0h4n changes are done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants