Skip to content
Snippets Groups Projects
Verified Commit 7b68bf80 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Dynamic names for default retention policies

InfluxDB decided that as of 1.0.0 it would be a good idea to rename the
default retention policy from "default" to "autogen" and then hardcode
this name all over the place. This means that we not only have to handle
this when creating retention policies, we also have to make sure all
queries use the right policy name for input measurements.

Fixes #1
parent f188bfb3
No related branches found
No related tags found
No related merge requests found
Showing
with 30 additions and 21 deletions
Loading
Loading
@@ -19,10 +19,10 @@ task :policies do
 
policies = CLIENT.list_retention_policies(db)
policy_names = policies.map { |h| h['name'] }
default = policies.find { |h| h['name'] == 'default' }
default = policies.find { |h| h['default'] }
 
unless default['duration'] == '1h'
CLIENT.alter_retention_policy('default', db, '1h', 1, true)
CLIENT.alter_retention_policy(default['name'], db, '1h', 1, true)
end
 
unless policy_names.include?('downsampled')
Loading
Loading
@@ -41,6 +41,8 @@ end
desc 'Updates the continuous queries in the database'
task :queries do
db = ENV.fetch('INFLUX_DATABASE')
policies = CLIENT.list_retention_policies(db)
default_retention_policy = policies.find { |h| h['default'] }.fetch('name')
 
Dir[File.join(QUERIES, '**', '*.txt')].each do |file|
name = File.basename(file, File.extname(file))
Loading
Loading
@@ -52,6 +54,13 @@ task :queries do
raise "The query in #{file} must specify the database using `ON $DATABASE`"
end
 
if query.include?('$DEFAULT_RETENTION_POLICY')
query.gsub!('$DEFAULT_RETENTION_POLICY', default_retention_policy)
else
raise "The query in #{file} must specify the default retention policy " \
"for source measurements using `$DEFAULT_RETENTION_POLICY`"
end
puts "Creating continuous query #{name}"
 
CLIENT.query("DROP CONTINUOUS QUERY #{name} ON #{db}")
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@ CREATE CONTINUOUS QUERY builds_per_project_per_hour ON $DATABASE
BEGIN
SELECT sum(count) AS "count"
INTO year.builds_per_project_per_hour
FROM "default".events
FROM "$DEFAULT_RETENTION_POLICY".events
WHERE "event" = 'build_found'
GROUP BY time(1h), project
END
Loading
Loading
@@ -2,7 +2,7 @@ CREATE CONTINUOUS QUERY commits_pushed_to_master_per_hour ON $DATABASE
BEGIN
SELECT sum(count) AS "count"
INTO year.commits_pushed_to_master_per_hour
FROM "default".events
FROM "$DEFAULT_RETENTION_POLICY".events
WHERE "event" = 'push_commit'
AND "branch" = 'master'
GROUP BY time(1h)
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@ CREATE CONTINUOUS QUERY commits_pushed_to_non_master_per_hour ON $DATABASE
BEGIN
SELECT sum(count) AS "count"
INTO year.commits_pushed_to_non_master_per_hour
FROM "default".events
FROM "$DEFAULT_RETENTION_POLICY".events
WHERE "event" = 'push_commit'
AND "branch" != 'master'
GROUP BY time(1h)
Loading
Loading
Loading
Loading
@@ -2,6 +2,6 @@ CREATE CONTINUOUS QUERY events_per_hour ON $DATABASE
BEGIN
SELECT sum(count) AS "count"
INTO year.events_per_hour
FROM "default".events
FROM "$DEFAULT_RETENTION_POLICY".events
GROUP BY time(1h), "event"
END
Loading
Loading
@@ -4,7 +4,7 @@ BEGIN
percentile("duration", 95) AS duration_95th,
percentile("duration", 99) AS duration_99th
INTO downsampled.grape_git_timings_per_action
FROM "default".rails_method_calls
FROM "$DEFAULT_RETENTION_POLICY".rails_method_calls
WHERE (action !~ /.+/ OR action =~ /^Grape#/)
AND method =~ /^(Rugged|Gitlab::Git)/
GROUP BY time(1m), action
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ BEGIN
percentile(banzai_cacheless_render_cpu_time, 99) AS cacheless_cpu_99th,
sum(banzai_cacheless_render_call_count) AS cacheless_call_count
INTO downsampled.grape_markdown_render_timings_overall
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE (action !~ /.+/ OR action =~ /^Grape#/)
AND (banzai_cached_render_call_count > 0 OR banzai_cacheless_render_call_count > 0)
GROUP BY time(1m)
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ BEGIN
percentile(banzai_cacheless_render_cpu_time, 99) AS cacheless_cpu_99th,
sum(banzai_cacheless_render_call_count) AS cacheless_call_count
INTO downsampled.grape_markdown_render_timings_per_action
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE (action !~ /.+/ OR action =~ /^Grape#/)
AND (banzai_cached_render_call_count > 0 OR banzai_cacheless_render_call_count > 0)
GROUP BY time(1m), action
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ BEGIN
percentile("duration", 95) AS duration_95th,
percentile("duration", 99) AS duration_99th
INTO downsampled.grape_markdown_timings_overall
FROM "default".rails_method_calls
FROM "$DEFAULT_RETENTION_POLICY".rails_method_calls
WHERE (action !~ /.+/ OR action =~ /^Grape#/)
AND method =~ /^Banzai/
GROUP BY time(1m)
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ BEGIN
percentile(call_count, 95) AS call_count_95th,
percentile(call_count, 99) AS call_count_99th
INTO downsampled.grape_method_call_timings_per_action_and_method
FROM "default".rails_method_calls
FROM "$DEFAULT_RETENTION_POLICY".rails_method_calls
WHERE action !~ /.+/ OR action =~ /^Grape#/
GROUP BY time(1m), method, action
END
Loading
Loading
@@ -10,7 +10,7 @@ BEGIN
percentile(call_count, 95) AS call_count_95th,
percentile(call_count, 99) AS call_count_99th
INTO downsampled.grape_method_call_timings_per_method
FROM "default".rails_method_calls
FROM "$DEFAULT_RETENTION_POLICY".rails_method_calls
WHERE action !~ /.+/ OR action =~ /^Grape#/
GROUP BY time(1m), method
END
Loading
Loading
@@ -9,7 +9,7 @@ BEGIN
percentile(cache_read_miss_count, 95) AS cache_read_miss_count_95th,
percentile(cache_read_miss_count, 99) AS cache_read_miss_count_99th
INTO downsampled.grape_transaction_cache_counts_overall
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/ OR action =~ /^Grape#/
GROUP BY time(1m)
END
Loading
Loading
@@ -9,7 +9,7 @@ BEGIN
percentile(cache_read_miss_count, 95) AS cache_read_miss_count_95th,
percentile(cache_read_miss_count, 99) AS cache_read_miss_count_99th
INTO downsampled.grape_transaction_cache_counts_per_action
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/ OR action =~ /^Grape#/
GROUP BY time(1m), action
END
Loading
Loading
@@ -2,7 +2,7 @@ CREATE CONTINUOUS QUERY grape_transaction_counts_overall ON $DATABASE
BEGIN
SELECT count("duration") AS count
INTO downsampled.grape_transaction_counts_overall
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/
OR action =~ /^Grape#/
GROUP BY time(1m)
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@ CREATE CONTINUOUS QUERY grape_transaction_counts_per_action ON $DATABASE
BEGIN
SELECT count("duration") AS count
INTO downsampled.grape_transaction_counts_per_action
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/
OR action =~ /^Grape#/
GROUP BY time(1m), action
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ BEGIN
percentile(new_redis_connections, 95) AS new_redis_connections_95th,
percentile(new_redis_connections, 99) AS new_redis_connections_99th
INTO downsampled.grape_transaction_new_redis_connection_counts_overall
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/ OR action =~ /^Grape#/
GROUP BY time(1m)
END
Loading
Loading
@@ -5,7 +5,7 @@ BEGIN
percentile(new_redis_connections, 95) AS new_redis_connections_95th,
percentile(new_redis_connections, 99) AS new_redis_connections_99th
INTO downsampled.grape_transaction_new_redis_connection_counts_per_action
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/
OR action =~ /^Grape#/
GROUP BY time(1m), action
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ BEGIN
percentile(sql_count, 95) AS sql_count_95th,
percentile(sql_count, 99) AS sql_count_99th
INTO downsampled.grape_transaction_sql_counts_overall
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/ OR action =~ /^Grape#/
GROUP BY time(1m)
END
Loading
Loading
@@ -5,7 +5,7 @@ BEGIN
percentile(sql_count, 95) AS sql_count_95th,
percentile(sql_count, 99) AS sql_count_99th
INTO downsampled.grape_transaction_sql_counts_per_action
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/ OR action =~ /^Grape#/
GROUP BY time(1m), action
END
Loading
Loading
@@ -29,7 +29,7 @@ BEGIN
percentile(rails_queue_duration, 95) AS rails_queue_duration_95th,
percentile(rails_queue_duration, 99) AS rails_queue_duration_99th
INTO downsampled.grape_transaction_timings_overall
FROM "default".rails_transactions
FROM "$DEFAULT_RETENTION_POLICY".rails_transactions
WHERE action !~ /.+/ OR action =~ /^Grape#/
GROUP BY time(1m)
END
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment