Skip to content

Conversation

alltilla
Copy link
Collaborator

@alltilla alltilla commented Sep 5, 2023

No description provided.

@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build FAILURE

@alltilla alltilla changed the title s3: add dest S3 Destination Sep 11, 2023
@alltilla alltilla marked this pull request as ready for review September 11, 2023 09:44
@alltilla
Copy link
Collaborator Author

This is now ready for review, we still need the reloc and metric labeling support in python, but the business logic is done.

@kira-syslogng
Copy link
Contributor

Build FAILURE

@alltilla alltilla force-pushed the s3-dest branch 4 times, most recently from bee6759 to 747691f Compare September 11, 2023 10:19
@kira-syslogng
Copy link
Contributor

Build FAILURE

@alltilla alltilla force-pushed the s3-dest branch 6 times, most recently from c5d4478 to e147ec5 Compare September 13, 2023 14:18
@OverOrion OverOrion self-requested a review September 15, 2023 08:46
Copy link
Collaborator

@OverOrion OverOrion left a comment

Choose a reason for hiding this comment

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

I had some minor remarks only, the overall picture is very great, thanks!

We also discussed the compress/compresslevel vs compresslevel only part, and we had agreed on keeping it the current way for easier configuration.

def __init__(
self,
path: Path,
compress: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

To me it seems that the compress field serves as a guard for compresslevel only. However as compresslevel is Optional[int], compress seems redundant because setting compression can be done by passing some level or just omitting it if no compression is required. How about removing it?



class S3Destination(LogDestination):
S3_OBJECT_TIMEOUT_INTERVAL = 60
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nitpicking]
I think S3_OBJECT_TIMEOUT_INTERVAL_SECONDS might be a bit more suitable name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, fixed!

Comment on lines +37 to +45

signal(SIGINT, SIG_IGN)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This stood out to me for a while, is it there to propagate the signal to syslog-ng?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be needed as we are running python in isolated mode, which means it should not install signal handles

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am still having a problem if I remove that line:

^C[2023-09-19T14:02:51.779809] syslog-ng shutting down; version='4.3.1.174.g93ca97d.dirty'
[2023-09-19T14:02:51.975195] Exception while calling a Python function; caller='d_s3#0', class='syslogng.modules.s3.S3Destination', function='deinit', exception='KeyboardInterrupt: '
Traceback (most recent call last):
  File "/home/alltilla/repos/syslog-ng/build/install/lib/syslog-ng/python/syslogng/modules/s3/s3_destination.py", line 148, in deinit
    def deinit(self) -> None:
KeyboardInterrupt

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This happens, when I Ctrl+C a running syslog-ng.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checked it with bare python and python -I, both of them catch SIGINT :/

$ sudo ps -o pid,caught,cmd -p 143434
    PID           CAUGHT CMD
 143434 0000000008000002 python3
$ sudo ps -o pid,caught,cmd -p 214536
    PID           CAUGHT CMD
 214536 0000000000000002 python3 -I
$ python -I
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> ^C
KeyboardInterrupt

self.object_key_timestamp: Optional[LogTemplate] = options["object_key_timestamp"]
self.message_template: LogTemplate = options["template"]
self.compression = bool(options["compression"])
self.compresslevel = int(options["compresslevel"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be Optional[int], shouldn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, setting the defaults for each option is the responsibility of the SCL. If the user uses this class as a python dest, and they mess this up, they will see an error.

        except KeyError:
            assert False, (
                f"S3: {str(exc_info()[1])[1:-1]}() option is missing. "
                "If you are using this driver via the python() destination, please use the s3() driver directly. "
                "The option validation and propagation should be done by the s3.conf SCL."
            )
block destination s3(
    url("")
    bucket()
    access_key()
    secret_key()
    object_key()
    object_key_timestamp("")
    template("${MESSAGE}\n")
    compression(no)
    compresslevel(9)

return False

if retries == 0:
self.logger.error("Upload queue full, waiting for available space")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.logger.error("Upload queue full, waiting for available space")
self.logger.error("Upload queue is full, waiting for available space")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, fixed!



class S3Object:
MIN_CHUNK_SIZE = 5 * 1024 * 1024
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
MIN_CHUNK_SIZE = 5 * 1024 * 1024
MIN_CHUNK_SIZE_BYTES = 5 * 1024 * 1024

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, fixed!

Comment on lines +31 to +32
compression(no)
compresslevel(9)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about removing the compression option and using compresslevel(0) as a way to disable compression?

self.object_key_timestamp: Optional[LogTemplate] = options["object_key_timestamp"]
self.message_template: LogTemplate = options["template"]
self.compression = bool(options["compression"])
self.compresslevel = int(options["compresslevel"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also please also add some sanity checks regarding its value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, fixed!

@alltilla alltilla force-pushed the s3-dest branch 2 times, most recently from bbdf4b7 to 5ec14e8 Compare September 18, 2023 11:00
@alltilla
Copy link
Collaborator Author

@OverOrion Thanks for the comments. As we discussed IRL, I have kept compress() and compresslevel() as they were, just added a sanity check.

@alltilla alltilla added this to the syslog-ng 4.4 milestone Sep 19, 2023
@MrAnno MrAnno self-requested a review September 20, 2023 10:39
@alltilla alltilla requested a review from MrAnno September 22, 2023 07:45
It is needed for SCLs, where the 2 double-quotes get resolved
to nothing. We want to have na empty template in that case.

Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Copy link
Collaborator

@MrAnno MrAnno left a comment

Choose a reason for hiding this comment

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

👍🏻 👍🏻
(please squash the fixups)

Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Python 3.6 does not support fres boto3 and botocore versions, also
compiling type hinted code (which is done for some reason during
setup.py) does not seem to work.

We tackle these 2 in the following ways:

In requirements.txt we allow installing older boto3 and botocore
versions. We should not install them at all, but filtering based
on the python version would be complex.

We skip adding the s3 module to the packages in setup.py for <= 3.6.

The only platform we support and has 3.6 is centos-7. We can remove
these workarounds when the centos-7 support is dropped (June 2024).

Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
@MrAnno MrAnno merged commit 7a860fa into syslog-ng:master Sep 22, 2023
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.

5 participants