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
d9f337fe
Commit
d9f337fe
authored
Jul 29, 2021
by
Piotr Skorupa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add metric definition schema validation spec
parent
5dce47e8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
4 deletions
+24
-4
config/metrics/objects_schemas/projects_with_enabled_alert_integrations_histogram.json
...s/projects_with_enabled_alert_integrations_histogram.json
+1
-1
ee/spec/config/metrics/every_metric_definition_spec.rb
ee/spec/config/metrics/every_metric_definition_spec.rb
+11
-2
lib/gitlab/usage/metrics/instrumentations/collected_data_categories_metric.rb
...rics/instrumentations/collected_data_categories_metric.rb
+1
-1
spec/support/matchers/schema_matcher.rb
spec/support/matchers/schema_matcher.rb
+11
-0
No files found.
config/metrics/objects_schemas/projects_with_enabled_alert_integrations_histogram.json
View file @
d9f337fe
{
"type"
:
"object"
,
"description"
:
"Histogram (buckets 1 to 100) of projects with at least 1 enabled integration"
"description"
:
"Histogram (buckets 1 to 100) of projects with at least 1 enabled integration"
,
"propertyNames"
:
{
"pattern"
:
"^[1-9][0-9]?0?$"
}
...
...
ee/spec/config/metrics/every_metric_definition_spec.rb
View file @
d9f337fe
...
...
@@ -51,7 +51,6 @@ RSpec.describe 'Every metric definition' do
Gitlab
::
Usage
::
MetricDefinition
.
definitions
.
select
{
|
k
,
v
|
v
.
respond_to?
(
:value_json_schema
)
}
.
keys
end
# Recursively traverse nested Hash of a generated Usage Ping to return an Array of key paths
...
...
@@ -67,7 +66,7 @@ RSpec.describe 'Every metric definition' do
end
def
object_with_schema?
(
key_path
)
metric_files_with_schema
.
include?
(
key_path
)
metric_files_with_schema
.
keys
.
include?
(
key_path
)
end
before
do
...
...
@@ -81,4 +80,14 @@ RSpec.describe 'Every metric definition' do
it
'is included in the Usage Ping hash structure'
do
expect
(
metric_files_key_paths
).
to
match_array
(
usage_ping_key_paths
)
end
context
'with value json schema'
do
it
'has a valid structure'
do
metric_files_with_schema
.
each
do
|
key_path
,
metric
|
structure
=
usage_ping
.
dig
(
*
key_path
.
split
(
'.'
).
map
(
&
:to_sym
))
expect
(
structure
).
to
match_metric_definition_schema
(
metric
.
value_json_schema
)
end
end
end
end
lib/gitlab/usage/metrics/instrumentations/collected_data_categories_metric.rb
View file @
d9f337fe
...
...
@@ -6,7 +6,7 @@ module Gitlab
module
Instrumentations
class
CollectedDataCategoriesMetric
<
GenericMetric
value
do
::
ServicePing
::
PermitDataCategoriesService
.
new
.
execute
::
ServicePing
::
PermitDataCategoriesService
.
new
.
execute
.
to_a
end
end
end
...
...
spec/support/matchers/schema_matcher.rb
View file @
d9f337fe
...
...
@@ -45,6 +45,17 @@ RSpec::Matchers.define :match_response_schema do |schema, dir: nil, **options|
end
end
RSpec
::
Matchers
.
define
:match_metric_definition_schema
do
|
path
,
dir:
nil
,
**
options
|
match
do
|
data
|
schema_path
=
Pathname
.
new
(
Rails
.
root
.
join
(
dir
.
to_s
,
path
).
to_s
)
validator
=
SchemaPath
.
validator
(
schema_path
)
data
=
data
.
stringify_keys
if
data
.
is_a?
Hash
validator
.
valid?
(
data
)
end
end
RSpec
::
Matchers
.
define
:match_snowplow_schema
do
|
schema
,
dir:
nil
,
**
options
|
match
do
|
data
|
schema_path
=
Pathname
.
new
(
Rails
.
root
.
join
(
dir
.
to_s
,
'spec'
,
"fixtures/product_intelligence/
#{
schema
}
.json"
).
to_s
)
...
...
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