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

nixos/gitea: add cache option #108848

Closed
wants to merge 10 commits into from
Closed

Conversation

dadada
Copy link
Contributor

@dadada dadada commented Jan 9, 2021

This adds an option that sets up an in-memory cache.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@aanderse
Copy link
Member

aanderse commented Jan 9, 2021

Personally I would either call this option createRedisCacheLocally or create a few options so the hard-coded values you set can be configured:

services.gitea.redis.createLocally = true;
# something to configure db=0,pool_size=100,idle_timeout=180 like...
services.gitea.redis.database = 0;
services.gitea.redis.poolSize = 100;

I think my preference is to keep it simple with createRedisCacheLocally and let the user configure it themselves without this option if they need more customization (noting such in the description).

Why do I care about the name? useRedisCache sounds like it should be flexible enough to use a remote host. I like using the word Locally to indicate this is not the case.

Aside from that everything looks great. And keep in mind the naming is just my opinion. Maybe you disagree, in which case you can feel free to ignore me 😄

Aside from that everything looks fine from a quick glance.

ping @Ma27 for review - aren't you the maintainer of this module too? 🤔 If you're not you really should be 😄

@dadada
Copy link
Contributor Author

dadada commented Jan 9, 2021

I agree. Having more flexibility is probably a good idea.

Another way might be to match cfg.settings.cache.HOST and configure redis, memcached or other backends supported by gitea. I'm not sure if this might be too much hidden magic though. Setting an option in settings should really only add a setting to the configuration file and not have additional side effects. This is why having an option outside settings that configures something that just works would be preferable, I guess.

Exposing these settings in services.gitea.cache might be preferable, since gitea allows for multiple cache backends like Memcache and redis but afaik they are mutually exclusive. Caching to memory seems to be the default and does not take any extra options or configuration, so settings might be sufficient.

services.gitea.cache = {  
    enable = true; # default
    # Produces some thing like
    # HOST="redis://:macaron@127.0.0.1:6379/0?pool_size=100&idle_timeout=180s"
    "redis" =  {  # either "memory", "redis", or "memcache" with different options each
      user = "macaron"; # optional
      host = "127.0.0.1";
      port = 6379; # optional
      database = 0; # optional
      poolSize = 100; # optional
      idle_timeout = 180; # optional
    };
};
# This would produce 
# HOST="network=unix,addr=${redis.unixSocket},db=0,pool_size=100,idle_timeout=180"
services.gitea.cache = {
    enable = true;
    "redis".unixSocket = "/run/redis/redis.sock"; # mutually exclusive with (user, host, port)
}

For now, I'd like to only allow "redis" for the adapter, since Memcache might require additional configuration. Users can still set this up manually using the settings.

@dadada
Copy link
Contributor Author

dadada commented Jan 9, 2021

    "redis".unixSocket = "/run/redis/redis.sock"; # mutually exclusive with (user, host, port)

Or just "redis".useLocal = true and do the magic there.

@dadada
Copy link
Contributor Author

dadada commented Jan 9, 2021

services.gitea.cache.<name>.enable should always default to false, then we can leave out services.gitea.cache.<name>.unixSocket and just configure the unix socket as a sane default when services.gitea.cache."redis.enable = true. So either gitea.cache.memcache.enable or gitea.cache.redis.enable can be true.

@aanderse
Copy link
Member

aanderse commented Jan 9, 2021

That sounds reasonable 👍

@Ma27
Copy link
Member

Ma27 commented Jan 9, 2021

I can leave a review later tonight or tomorrow @aanderse (this also applies to the other PRs where I got CCed :)).

ping @Ma27 for review - aren't you the maintainer of this module too? thinking If you're not you really should be smile

Since most of the modules don't have a meta.maintainers field (I don't really know about this guideline for modules tbh) I usually consider the package maintainers as responsible for the module as well unless stated otherwise... But yeah, guess I'll add myself there as well later :)

@Ma27
Copy link
Member

Ma27 commented Jan 10, 2021

@GrahamcOfBorg test gitea

@dadada dadada changed the title nixos/gitea: add option useRedisCache nixos/gitea: add option cache Jan 17, 2021
@dadada dadada changed the title nixos/gitea: add option cache nixos/gitea: add cache option Jan 17, 2021
@dadada
Copy link
Contributor Author

dadada commented Jan 17, 2021

Still needs some more automated tests. The redis cache already works fine using the unix socket.

@dadada dadada force-pushed the dadada/gitea-redis-cache branch 6 times, most recently from ab1fc1a to d0b756c Compare January 17, 2021 19:10
nixos/tests/gitea.nix Outdated Show resolved Hide resolved
@dadada dadada force-pushed the dadada/gitea-redis-cache branch 2 times, most recently from b273b80 to 86aceb2 Compare January 23, 2021 18:07
@dadada
Copy link
Contributor Author

dadada commented Jan 23, 2021

Still needs some more automated tests. The redis cache already works fine using the unix socket.

Should have sufficient test coverage now. Ready for review.

@dadada dadada requested review from Ma27 and hmenke January 30, 2021 00:08
@dadada dadada requested review from hmenke and Ma27 and removed request for srhb, hmenke, Ma27 and aanderse May 9, 2021 10:15
@dadada
Copy link
Contributor Author

dadada commented May 9, 2021

@GrahamcOfBorg test gitea

Copy link
Member

@hmenke hmenke left a comment

Choose a reason for hiding this comment

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

I haven't tested it (I'm only using GItea with in-memory caching), but the module code looks totally sensible and there is a NixOS test. 👍

nixos/modules/services/misc/gitea.nix Outdated Show resolved Hide resolved
Uses gitea's default cache settings or the settings provided in the
configuration.
@dadada
Copy link
Contributor Author

dadada commented May 15, 2021

Is it possible to declare a type in a way that it can be a submodule with contents either like cache.redis, cache.memcached or cache.memory? Something similar to

cache = mkOption {
  type = myUnionType [ redisCache memcachedCache memory ];
};

where the list elements are the possible submodules.

@stale
Copy link

stale bot commented Nov 16, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 16, 2021
@SuperSandro2000
Copy link
Member

I think you want to construct a generic option which has a option for the cache type instead.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 6, 2023
@SuperSandro2000 SuperSandro2000 added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 6, 2023
@dadada dadada closed this Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants