Skip to content

Commit

Permalink
Add support for Redis6 features
Browse files Browse the repository at this point in the history
  • Loading branch information
fraenki committed Apr 6, 2022
1 parent 44f6693 commit 98f5f01
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 6 deletions.
59 changes: 57 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,47 @@
# Only set if cluster_enabled is true
# @param instances
# Iterate through multiple instance configurations
# @param io_threads
# Number of threads to handle IO operations in Redis
# @param io_threads_do_reads
# Enabled/disable io_threads to handle reads
# @param cluster_allow_reads_when_down
# Allows nodes to serve read data while cluster status is down
# @param cluster_replica_no_failover
# Disabled automatic failover for replica
# @param dynamic_hz
# When dynamic HZ is enabled, the actual configured HZ will be used
# as a baseline, but multiples of the configured HZ value will be actually
# used as needed once more clients are connected.
# @param activedefrag
# Enable/disable active defragmentation
# @param active_defrag_ignore_bytes
# Minimum amount of fragmentation waste to start active defrag
# Only set if activedefrag is true
# @param active_defrag_threshold_lower
# Minimum percentage of fragmentation to start active defrag
# Only set if activedefrag is true
# @param active_defrag_threshold_upper
# Maximum percentage of fragmentation at which we use maximum effort
# Only set if activedefrag is true
# @param active_defrag_cycle_min
# Minimal effort for defrag in CPU percentage, to be used when the lower
# threshold is reached
# Only set if activedefrag is true
# @param active_defrag_cycle_max
# Maximal effort for defrag in CPU percentage, to be used when the upper
# threshold is reached
# Only set if activedefrag is true
# @param active_defrag_max_scan_fields
# Maximum number of set/hash/zset/list fields that will be processed from
# the main dictionary scan
# Only set if activedefrag is true
# @param jemalloc_bg_thread
# Jemalloc background thread for purging will be enabled by default
# @param rdb_save_incremental_fsync
# When redis saves RDB file, if the following option is enabled
# the file will be fsync-ed every 32 MB of data generated.

class redis (
Boolean $activerehashing = true,
Boolean $aof_load_truncated = true,
Expand Down Expand Up @@ -301,8 +342,8 @@
Optional[Variant[String[1], Sensitive[String[1]]]] $masterauth = undef,
Integer[1] $maxclients = 10000,
$maxmemory = undef,
$maxmemory_policy = undef,
$maxmemory_samples = undef,
Optional[Redis::MemoryPolicy] $maxmemory_policy = undef,
Optional[Integer[1, 10]] $maxmemory_samples = undef,
Integer[0] $min_slaves_max_lag = 10,
Integer[0] $min_slaves_to_write = 0,
Array[Stdlib::Absolutepath] $modules = [],
Expand Down Expand Up @@ -372,6 +413,20 @@
Boolean $cluster_require_full_coverage = true,
Integer[0] $cluster_migration_barrier = 1,
Hash[String[1], Hash] $instances = {},
Optional[Integer[1]] $io_threads = undef,
Optional[Boolean] $io_threads_do_reads = undef,
Optional[Boolean] $cluster_allow_reads_when_down = undef,
Optional[Boolean] $cluster_replica_no_failover = undef,
Optional[Boolean] $dynamic_hz = undef,
Optional[Boolean] $activedefrag = undef,
String[1] $active_defrag_ignore_bytes = '100mb',
Integer[1, 100] $active_defrag_threshold_lower = 10,
Integer[1, 100] $active_defrag_threshold_upper = 100,
Integer[1, 100] $active_defrag_cycle_min = 1,
Integer[1, 100] $active_defrag_cycle_max = 100,
Integer[1] $active_defrag_max_scan_fields = 1000,
Optional[Boolean] $jemalloc_bg_thread = undef,
Boolean $rdb_save_incremental_fsync = true,
) inherits redis::params {
contain redis::preinstall
contain redis::install
Expand Down
68 changes: 68 additions & 0 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,46 @@
# Minimum number of slaves master will remain connected with, for another
# slave to migrate to a master which is no longer covered by any slave Only
# set if cluster_enabled is true
# @param io_threads
# Number of threads to handle IO operations in Redis
# @param io_threads_do_reads
# Enabled/disable io_threads to handle reads
# @param cluster_allow_reads_when_down
# Allows nodes to serve read data while cluster status is down
# @param cluster_replica_no_failover
# Disabled automatic failover for replica
# @param dynamic_hz
# When dynamic HZ is enabled, the actual configured HZ will be used
# as a baseline, but multiples of the configured HZ value will be actually
# used as needed once more clients are connected.
# @param activedefrag
# Enable/disable active defragmentation
# @param active_defrag_ignore_bytes
# Minimum amount of fragmentation waste to start active defrag
# Only set if activedefrag is true
# @param active_defrag_threshold_lower
# Minimum percentage of fragmentation to start active defrag
# Only set if activedefrag is true
# @param active_defrag_threshold_upper
# Maximum percentage of fragmentation at which we use maximum effort
# Only set if activedefrag is true
# @param active_defrag_cycle_min
# Minimal effort for defrag in CPU percentage, to be used when the lower
# threshold is reached
# Only set if activedefrag is true
# @param active_defrag_cycle_max
# Maximal effort for defrag in CPU percentage, to be used when the upper
# threshold is reached
# Only set if activedefrag is true
# @param active_defrag_max_scan_fields
# Maximum number of set/hash/zset/list fields that will be processed from
# the main dictionary scan
# Only set if activedefrag is true
# @param jemalloc_bg_thread
# Jemalloc background thread for purging will be enabled by default
# @param rdb_save_incremental_fsync
# When redis saves RDB file, if the following option is enabled
# the file will be fsync-ed every 32 MB of data generated.
define redis::instance (
Boolean $activerehashing = $redis::activerehashing,
Boolean $aof_load_truncated = $redis::aof_load_truncated,
Expand Down Expand Up @@ -327,6 +367,20 @@
Stdlib::Absolutepath $pid_file = "/var/run/${service_name}/redis.pid",
Variant[Stdlib::Absolutepath, Enum['']] $unixsocket = "/var/run/${service_name}/redis.sock",
Stdlib::Absolutepath $workdir = "${redis::workdir}/redis-server-${name}",
Optional[Integer[1]] $io_threads = $redis::io_threads,
Optional[Boolean] $io_threads_do_reads = $redis::io_threads_do_reads,
Optional[Boolean] $cluster_allow_reads_when_down = $redis::cluster_allow_reads_when_down,
Optional[Boolean] $cluster_replica_no_failover = $redis::cluster_replica_no_failover,
Optional[Boolean] $dynamic_hz = $redis::dynamic_hz,
Optional[Boolean] $activedefrag = $redis::activedefrag,
String[1] $active_defrag_ignore_bytes = $redis::active_defrag_ignore_bytes,
Integer[1, 100] $active_defrag_threshold_lower = $redis::active_defrag_threshold_lower,
Integer[1, 100] $active_defrag_threshold_upper = $redis::active_defrag_threshold_upper,
Integer[1, 100] $active_defrag_cycle_min = $redis::active_defrag_cycle_min,
Integer[1, 100] $active_defrag_cycle_max = $redis::active_defrag_cycle_max,
Integer[1] $active_defrag_max_scan_fields = $redis::active_defrag_max_scan_fields,
Optional[Boolean] $jemalloc_bg_thread = $redis::jemalloc_bg_thread,
Optional[Boolean] $rdb_save_incremental_fsync = $redis::rdb_save_incremental_fsync,
) {
if $title == 'default' {
$redis_file_name_orig = $config_file_orig
Expand Down Expand Up @@ -499,6 +553,20 @@
tls_cluster => $tls_cluster,
tls_prefer_server_ciphers => $tls_prefer_server_ciphers,
modules => $modules,
io_threads => $io_threads,
io_threads_do_reads => $io_threads_do_reads,
cluster_allow_reads_when_down => $cluster_allow_reads_when_down,
cluster_replica_no_failover => $cluster_replica_no_failover,
dynamic_hz => $dynamic_hz,
activedefrag => $activedefrag,
active_defrag_ignore_bytes => $active_defrag_ignore_bytes,
active_defrag_threshold_lower => $active_defrag_threshold_lower,
active_defrag_threshold_upper => $active_defrag_threshold_upper,
active_defrag_cycle_min => $active_defrag_cycle_min,
active_defrag_cycle_max => $active_defrag_cycle_max,
active_defrag_max_scan_fields => $active_defrag_max_scan_fields,
jemalloc_bg_thread => $jemalloc_bg_thread,
rdb_save_incremental_fsync => $rdb_save_incremental_fsync,
}
),
}
Expand Down
144 changes: 140 additions & 4 deletions spec/classes/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,27 +576,27 @@ class { 'redis::globals':
describe 'with parameter maxmemory_policy' do
let(:params) do
{
maxmemory_policy: '_VALUE_'
maxmemory_policy: 'noeviction'
}
end

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{maxmemory-policy.*_VALUE_}
'content' => %r{maxmemory-policy.*noeviction}
)
}
end

describe 'with parameter maxmemory_samples' do
let(:params) do
{
maxmemory_samples: '_VALUE_'
maxmemory_samples: 9
}
end

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{maxmemory-samples.*_VALUE_}
'content' => %r{maxmemory-samples.*9}
)
}
end
Expand Down Expand Up @@ -1478,6 +1478,142 @@ class { 'redis::globals':
with_content(%r{^loadmodule /root/nullmodule.so$})
}
end

describe 'test io-threads for redis6' do
let(:params) do
{
io_threads: 4
}
end

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^io-threads 4$}
)
}
end

describe 'test io-threads-do-reads for redis6' do
let(:params) do
{
io_threads_do_reads: true,
}
end

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^io-threads-do-reads yes$}
)
}
end

describe 'test dynamic-hz for redis6' do
let(:params) do
{
dynamic_hz: true,
}
end

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^dynamic-hz yes$}
)
}
end

describe 'test activedefrag for redis6' do
let(:params) do
{
activedefrag: true,
}
end

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^activedefrag yes$}
)
}
end

describe 'test jemalloc-bg-thread for redis6' do
let(:params) do
{
jemalloc_bg_thread: true,
}
end

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^jemalloc-bg-thread yes$}
)
}
end

describe 'test activedefrag configuration for redis6' do
let(:params) do
{
activedefrag: true,
active_defrag_ignore_bytes: '200mb',
active_defrag_threshold_lower: 11,
active_defrag_threshold_upper: 99,
active_defrag_cycle_min: 7,
active_defrag_cycle_max: 23,
active_defrag_max_scan_fields: 1341,
}
end

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^activedefrag yes$}
)
}

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^active-defrag-ignore-bytes 200mb$}
)
}

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^active-defrag-threshold-lower 11$}
)
}

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^active-defrag-threshold-upper 99$}
)
}

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^active-defrag-cycle-min 7$}
)
}

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^active-defrag-cycle-max 23$}
)
}

it {
is_expected.to contain_file(config_file_orig).with(
'content' => %r{^active-defrag-max-scan-fields 1341$}
)
}
end

describe 'test rdb-save-incremental-fsync for redis6' do
let(:params) do
{
rdb_save_incremental_fsync: true,
}
end

it { is_expected.to contain_file(config_file_orig).with('content' => %r{^rdb-save-incremental-fsync yes$}) }
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/type_aliases/memorypolicy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'Redis::MemoryPolicy' do
it { is_expected.to allow_values('volatile-lru', 'allkeys-lru', 'volatile-lfu', 'allkeys-lfu', 'volatile-random', 'allkeys-random', 'volatile-ttl', 'noeviction') }
it { is_expected.not_to allow_value(nil) }
it { is_expected.not_to allow_value('') }
end
Loading

0 comments on commit 98f5f01

Please sign in to comment.