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

redis: Configurable Database #50

Merged
merged 1 commit into from
Aug 2, 2024
Merged

redis: Configurable Database #50

merged 1 commit into from
Aug 2, 2024

Conversation

oxzi
Copy link
Member

@oxzi oxzi commented Jul 29, 2024

A Redis server might support multiple databases, allowing to use the same Redis for different applications. The database can either be configured for the configuration or later changed via SELECT. By default, the database 0 will be used.

While both the used go-redis library and even Icinga 2 support this feature, we should expose this here and make this configurable.

As discussed in Icinga DB issue #676, this is not something one might want to encourage all users to use. However, there are definitely setups where this option might come in handy.

A Redis server might support multiple databases, allowing to use the
same Redis for different applications. The database can either be
configured for the configuration or later changed via SELECT[0]. By
default, the database 0 will be used.

While both the used go-redis library and even Icinga 2[1] support this
feature, we should expose this here and make this configurable.

As discussed in Icinga DB issue #676[2], this is not something one might
want to encourage all users to use. However, there are definitely setups
where this option might come in handy.

[0]: https://redis.io/docs/latest/commands/select/
[1]: https://github.com/Icinga/icinga2/blob/bca1a8447af26313123183efa863f947f9590731/lib/icingadb/icingadb.ti#L23
[2]: Icinga/icingadb#676
@oxzi oxzi added the enhancement New feature or request label Jul 29, 2024
@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Jul 29, 2024
@oxzi oxzi linked an issue Jul 29, 2024 that may be closed by this pull request
Copy link
Member

@lippserd lippserd left a comment

Choose a reason for hiding this comment

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

I would also change GetAddr() to include the database index, if other than 0. In Icinga DB, we are using that function to log where we connect to.

@oxzi
Copy link
Member Author

oxzi commented Aug 2, 2024

I would also change GetAddr() to include the database index, if other than 0. In Icinga DB, we are using that function to log where we connect to.

I like the idea, but the GetAddr method feels like the wrong place for me. During Icinga DB's startup, an implementation of this method is called both for Redis and for the relational database. Both are currently reporting the address of the service. The function name does not match protocol-specific information. Furthermore, no such data is logged for the database.

2024-08-01T14:07:41.794Z        INFO    icingadb        Connecting to database at 'mysql.example.com:3306'
2024-08-01T14:07:41.796Z        INFO    icingadb        Connecting to Redis at 'redis.example.com:6380'

How about introducing a new method for both db.DB and redis.Client to report domain specific connection details? Like, for example:

2024-08-01T14:07:41.794Z        INFO    icingadb        Connecting to database at "mysql.example.com:3306", type is mysql with user "foo" against database "icingadb"
2024-08-01T14:07:41.796Z        INFO    icingadb        Connecting to Redis at "redis.example.com:6380", with user "bar" against database 23

EDIT: I did a thing in #53.

oxzi added a commit that referenced this pull request Aug 2, 2024
The idea of a more informative connection information string was brought
up in #50[0]. Currently, at least Icinga DB and Icinga Notifications are
logging their connection target after startup. This information,
however, is quite vague and was now extended to contain, e.g., if TLS is
used, the username, the database.

>  INFO    icingadb        Connecting to database at "localhost:3306" as user "icingadb" against database "icingadb" as "mysql"
>  INFO    icingadb        Connecting to Redis at "localhost:6380" as user "foo" against database 7

The previously used method GetAddr does, however, not really represent
the required information. That's why it was removed and the fmt.Stringer
was implemented. This makes a small change necessary after updating the
icinga-go-library, like:

```
-               logger.Infof("Connecting to database at '%s'", db.GetAddr())
+               logger.Infof("Connecting to database at %s", db)
```

[0] #50 (review)
@lippserd
Copy link
Member

lippserd commented Aug 2, 2024

I would also change GetAddr() to include the database index, if other than 0. In Icinga DB, we are using that function to log where we connect to.

I like the idea, but the GetAddr method feels like the wrong place for me. During Icinga DB's startup, an implementation of this method is called both for Redis and for the relational database. Both are currently reporting the address of the service. The function name does not match protocol-specific information. Furthermore, no such data is logged for the database.

GetAddr() was only introduced for logging, so this method needs to be changed or removed if we do something else. But ...

EDIT: I did a thing in #53.

I will write something there and we can leave this PR as it is.

@julianbrost julianbrost merged commit 64c2bc4 into main Aug 2, 2024
2 checks passed
@julianbrost julianbrost deleted the redis-db-config branch August 2, 2024 10:45
oxzi added a commit that referenced this pull request Aug 8, 2024
The idea of a more informative connection information string was brought
up in #50[0]. Currently, at least Icinga DB and Icinga Notifications are
logging their connection target after startup. This information,
however, is quite vague and was now extended to contain, e.g., if TLS is
used, the username, the database.

> INFO    icingadb        Connecting to database at 'mysql://icingadb@localhost:3306/icingadb'
> INFO    icingadb        Connecting to Redis at 'redis://localhost:6380'

Furthermore, the zapcore.ObjectMarshaler interface was implemented,
allowing both *db.DB and *redis.Client to be used as a zap logging
field, showing the address.

[0] #50 (review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redis DB Index should be configurable
4 participants