Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
53166a26
Commit
53166a26
authored
May 20, 2021
by
Hordur Freyr Yngvason
Committed by
Mayra Cabrera
May 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backfill clusters_integration_prometheus.enabled
parent
2ae25491
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
0 deletions
+128
-0
changelogs/unreleased/migrate-prometheus-application-status-to-integration-enabled.yml
...-prometheus-application-status-to-integration-enabled.yml
+5
-0
db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb
...04931_backfill_clusters_integration_prometheus_enabled.rb
+42
-0
db/schema_migrations/20210519104931
db/schema_migrations/20210519104931
+1
-0
spec/migrations/backfill_clusters_integration_prometheus_enabled_spec.rb
.../backfill_clusters_integration_prometheus_enabled_spec.rb
+80
-0
No files found.
changelogs/unreleased/migrate-prometheus-application-status-to-integration-enabled.yml
0 → 100644
View file @
53166a26
---
title
:
Backfill clusters_integration_prometheus.enabled
merge_request
:
61502
author
:
type
:
changed
db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb
0 → 100644
View file @
53166a26
# frozen_string_literal: true
class
BackfillClustersIntegrationPrometheusEnabled
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
def
up
ApplicationRecord
.
connection
.
execute
(
<<~
SQL
.
squish
)
WITH executed_at AS (VALUES (TIMEZONE('UTC', NOW())))
INSERT INTO clusters_integration_prometheus(
cluster_id,
enabled,
encrypted_alert_manager_token,
encrypted_alert_manager_token_iv,
created_at,
updated_at
)
SELECT
cluster_id,
true,
encrypted_alert_manager_token,
encrypted_alert_manager_token_iv,
(table executed_at),
(table executed_at)
FROM clusters_applications_prometheus
WHERE status IN (
3, /* installed */
11 /* externally installed */
)
ON CONFLICT(cluster_id) DO UPDATE SET
enabled = true,
encrypted_alert_manager_token = EXCLUDED.encrypted_alert_manager_token,
encrypted_alert_manager_token_iv = EXCLUDED.encrypted_alert_manager_token_iv,
updated_at = (table executed_at)
SQL
end
def
down
# Irreversible
end
end
db/schema_migrations/20210519104931
0 → 100644
View file @
53166a26
c31cb40b6251704c699e7fa3e7392bb9eb73fefcd5b0268e2b8fc58df9e6075e
\ No newline at end of file
spec/migrations/backfill_clusters_integration_prometheus_enabled_spec.rb
0 → 100644
View file @
53166a26
# frozen_string_literal: true
require
'spec_helper'
require_migration!
'backfill_clusters_integration_prometheus_enabled'
RSpec
.
describe
BackfillClustersIntegrationPrometheusEnabled
,
:migration
do
def
create_cluster!
(
label
=
rand
(
2
**
64
).
to_s
)
table
(
:clusters
).
create!
(
name:
"cluster:
#{
label
}
"
,
created_at:
1
.
day
.
ago
,
updated_at:
1
.
day
.
ago
)
end
def
create_clusters_applications_prometheus!
(
label
,
status
:,
cluster_id:
nil
)
table
(
:clusters_applications_prometheus
).
create!
(
cluster_id:
cluster_id
||
create_cluster!
(
label
).
id
,
status:
status
,
version:
"
#{
label
}
: version"
,
created_at:
1
.
day
.
ago
,
# artificially aged
updated_at:
1
.
day
.
ago
,
# artificially aged
encrypted_alert_manager_token:
"
#{
label
}
: token"
,
encrypted_alert_manager_token_iv:
"
#{
label
}
: iv"
)
end
def
create_clusters_integration_prometheus!
table
(
:clusters_integration_prometheus
).
create!
(
cluster_id:
create_cluster!
.
id
,
enabled:
false
,
created_at:
1
.
day
.
ago
,
updated_at:
1
.
day
.
ago
)
end
RSpec
::
Matchers
.
define
:be_enabled_and_match_application_values
do
|
application
|
match
do
|
actual
|
actual
.
enabled
==
true
&&
actual
.
encrypted_alert_manager_token
==
application
.
encrypted_alert_manager_token
&&
actual
.
encrypted_alert_manager_token_iv
==
application
.
encrypted_alert_manager_token_iv
end
end
describe
'#up'
do
it
'backfills the enabled status and alert manager credentials from clusters_applications_prometheus'
do
status_installed
=
3
status_externally_installed
=
11
status_installable
=
0
existing_integration
=
create_clusters_integration_prometheus!
unaffected_existing_integration
=
create_clusters_integration_prometheus!
app_installed
=
create_clusters_applications_prometheus!
(
'installed'
,
status:
status_installed
)
app_installed_existing_integration
=
create_clusters_applications_prometheus!
(
'installed, existing integration'
,
status:
status_installed
,
cluster_id:
existing_integration
.
cluster_id
)
app_externally_installed
=
create_clusters_applications_prometheus!
(
'externally installed'
,
status:
status_externally_installed
)
app_other_status
=
create_clusters_applications_prometheus!
(
'other status'
,
status:
status_installable
)
migrate!
integrations
=
table
(
:clusters_integration_prometheus
).
all
.
index_by
(
&
:cluster_id
)
expect
(
unaffected_existing_integration
.
reload
).
to
eq
unaffected_existing_integration
integration_installed
=
integrations
[
app_installed
.
cluster_id
]
expect
(
integration_installed
).
to
be_enabled_and_match_application_values
(
app_installed
)
expect
(
integration_installed
.
updated_at
).
to
be
>=
1
.
minute
.
ago
# recently updated
expect
(
integration_installed
.
updated_at
).
to
eq
(
integration_installed
.
created_at
)
# recently created
expect
(
existing_integration
.
reload
).
to
be_enabled_and_match_application_values
(
app_installed_existing_integration
)
expect
(
existing_integration
.
updated_at
).
to
be
>=
1
.
minute
.
ago
# recently updated
expect
(
existing_integration
.
updated_at
).
not_to
eq
(
existing_integration
.
created_at
)
# but not recently created
integration_externally_installed
=
integrations
[
app_externally_installed
.
cluster_id
]
expect
(
integration_externally_installed
).
to
be_enabled_and_match_application_values
(
app_externally_installed
)
expect
(
integration_externally_installed
.
updated_at
).
to
be
>=
1
.
minute
.
ago
# recently updated
expect
(
integration_externally_installed
.
updated_at
).
to
eq
(
integration_externally_installed
.
created_at
)
# recently created
expect
(
integrations
[
app_other_status
.
cluster_id
]).
to
be_nil
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment