On 30.06.2017 13:43, Andjelko Iharos wrote: > Hi all, > > I'd like to propose for discussion an improvement to the feedback > delivered by HAProxy over the stats socket. > > Currently the feedback of stats socket commands is inconsistent and it > can be difficult for external tools issuing socket commands to discern > whether the command was successful or not. > In case of commands that are intended to provide information, a wide > variety of text can be returned with no easy way to distinguish error > messages from expected feedback. Commands that aren't intended to > provide information (i.e. set server) can return a newline or a variety > of feedback text when successful, and when unsuccessful they return a > different variety of feedback text. > > I propose to: > - keep unmodified the feedback messages of successful commands intended > to provide information (i.e. show stat) so that no change is needed to > external tools parsing successful output > - keep unmodified the feedback of successful commands that return just a > newline > - modify feedback in all other cases to include a prefix of message > severity corresponding to syslog severity level > > The addition of a severity at the start of a feedback message would make > it easy for external tools to disregard debug, info and notice messages > and assume socket command was successful (messages with no prefix can be > considered info by default), and identify warning, err, crit, alert and > emerg messages as indicating a socket command was unsuccessful. > > Examples > > Current behavior: > > => set server bck1/srv1 state maint > <= "\n" > > => set server bck1/srv1 addr 127.0.0.1 port 8080 > <= "no need to change the addr, port changed from '80' to '8080' by > 'stats socket command'\n\n" > > => set server bck1/srv2 state maint > <= "No such backend.\n\n" > > Patched behavior: > > => set server bck1/srv1 state maint > <= "\n" > > => set server bck1/srv1 addr 127.0.0.1 port 8080 > <= "NOTICE: no need to change the addr, port changed from '80' to '8080' > by 'stats socket command'\n\n" > > => set server bck1/srv2 state maint > <= "ERR: No such backend.\n\n" > > > Should there be no objections to the proposal I will submit a patch for > review.
I had to deal with this issue recently as well but I'd rather like to see a more explicit and well defined response in all cases rather than the workaround proposed above. Its not clear why a warning should automatically mean the command was unsuccessful and identifying a specific error still requires string matches which breaks all clients the moment the wording is changed or a typo is fixed. I'd rather see something along the lines of error codes i.e. 0 for "Ok" and anything else for specific errors followed by the message e.g.: 0:Ok 1:No such backend 2:No such server in backend etc. This would allow tools working with the socket to always get consistent responses and enable them to only parse the response code to identify the response regardless of the message. This could either be introduced only in the current development version because of the compatibility breakage or a parameter could be introduced to configure the socket with the new "protocol". If that parameter is not set then the code could simply not be sent in the response and messages would be returned just as they are now. Regards, Dennis

