insights-api-common 5.0.2 → 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/insights/api/common/application_controller_mixins/request_path.rb +6 -2
- data/lib/insights/api/common/error_document.rb +2 -1
- data/lib/insights/api/common/filter.rb +14 -0
- data/lib/insights/api/common/graphql/generator.rb +8 -0
- data/lib/insights/api/common/graphql/templates/aggregate_model_type.erb +8 -0
- data/lib/insights/api/common/graphql/templates/aggregate_type.erb +14 -0
- data/lib/insights/api/common/graphql/templates/model_type.erb +13 -0
- data/lib/insights/api/common/graphql/templates/query_type.erb +21 -11
- data/lib/insights/api/common/logging.rb +21 -8
- data/lib/insights/api/common/version.rb +1 -1
- metadata +8 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43e76c5bf47d65b4040b8ed210158adaae8730ea0ceca8a5bd51816d6572e75c
|
4
|
+
data.tar.gz: eca7c58f7e1c6051ed91d31a77e37f7559113aaedc54d6640f5986efc23557cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '081dae0fe687ba670fc6f6f1ca3a15ce399c99b7c55bc6297cce261a818189bbb6674d44e96c93296394780c25169cd214680c42dc941b0ab83c6dcfe37df246'
|
7
|
+
data.tar.gz: d2f112e2339e2398c761e08f447e2aed84ba4a7b15c2ec7fc9371d9aea6602afdb4c9f6ec96ead262e2879ee6f849ab572a20aa1582180f13265899ab98bb245
|
@@ -44,10 +44,14 @@ module Insights
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def id_regexp(primary_collection_name)
|
47
|
-
@
|
47
|
+
@id_regexp_table ||= {}
|
48
|
+
|
49
|
+
if @id_regexp_table.empty? || @id_regexp_table[primary_collection_name].nil?
|
48
50
|
id_parameter = id_parameter_from_api_doc(primary_collection_name)
|
49
|
-
id_parameter ? id_parameter.fetch_path("schema", "pattern") : /^\d+$/
|
51
|
+
@id_regexp_table[primary_collection_name] = id_parameter ? id_parameter.fetch_path("schema", "pattern") : /^\d+$/
|
50
52
|
end
|
53
|
+
|
54
|
+
@id_regexp_table[primary_collection_name]
|
51
55
|
end
|
52
56
|
|
53
57
|
def id_parameter_from_api_doc(primary_collection_name)
|
@@ -4,7 +4,8 @@ module Insights
|
|
4
4
|
class ErrorDocument
|
5
5
|
def add(status = 400, message)
|
6
6
|
@status = status
|
7
|
-
|
7
|
+
safe_message = message.to_s.encode('UTF-8', :invalid => :replace, :undef => :replace)
|
8
|
+
errors << {"status" => status, "detail" => safe_message}
|
8
9
|
self
|
9
10
|
end
|
10
11
|
|
@@ -177,6 +177,20 @@ module Insights
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
|
+
def self.build_filtered_scope(scope, api_version, klass_name, filter)
|
181
|
+
return scope unless filter
|
182
|
+
|
183
|
+
openapi_doc = ::Insights::API::Common::OpenApi::Docs.instance[api_version]
|
184
|
+
openapi_schema_name, = ::Insights::API::Common::GraphQL::Generator.openapi_schema(openapi_doc, klass_name)
|
185
|
+
|
186
|
+
action_parameters = ActionController::Parameters.new(filter)
|
187
|
+
definitions = openapi_doc.definitions
|
188
|
+
|
189
|
+
association_attribute_properties = association_attribute_properties(definitions, action_parameters)
|
190
|
+
|
191
|
+
new(scope, action_parameters, definitions[openapi_schema_name], association_attribute_properties).apply
|
192
|
+
end
|
193
|
+
|
180
194
|
def timestamp(k, val)
|
181
195
|
if val.kind_of?(Hash)
|
182
196
|
val.each do |comparator, value|
|
@@ -164,8 +164,16 @@ module Insights
|
|
164
164
|
|
165
165
|
graphql_model_type_template = ERB.new(template("model_type"), nil, '<>').result(binding)
|
166
166
|
graphql_namespace.module_eval(graphql_model_type_template)
|
167
|
+
|
168
|
+
unless graphql_namespace.const_defined?("#{klass_name}AggregateType", false)
|
169
|
+
graphql_aggregate_model_type_template = ERB.new(template("aggregate_model_type"), nil, '<>').result(binding)
|
170
|
+
graphql_namespace.module_eval(graphql_aggregate_model_type_template)
|
171
|
+
end
|
167
172
|
end
|
168
173
|
|
174
|
+
graphql_aggregate_type_template = ERB.new(template("aggregate_type"), nil, '<>').result(binding)
|
175
|
+
graphql_namespace.module_eval(graphql_aggregate_type_template)
|
176
|
+
|
169
177
|
graphql_query_type_template = ERB.new(template("query_type"), nil, '<>').result(binding)
|
170
178
|
graphql_namespace.module_eval(graphql_query_type_template)
|
171
179
|
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%= klass_name %>AggregateType = ::GraphQL::ObjectType.define do
|
2
|
+
name "<%= klass_name %>AggregateType"
|
3
|
+
description "A <%= klass_name %>AggregateType to wrap metrics aggregation"
|
4
|
+
|
5
|
+
field :aggregate, AggregateType do
|
6
|
+
resolve ->(object, _args, _ctx) { object }
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
AggregateType = ::GraphQL::ObjectType.define do
|
2
|
+
name "AggregateType"
|
3
|
+
description "A AggregateType type for aggregation metrics"
|
4
|
+
|
5
|
+
field :total_count, !types.Int do
|
6
|
+
resolve ->(object, _args, _ctx) {
|
7
|
+
if object.kind_of?(QueryRelation) # from nested aggregation
|
8
|
+
object.count # count is array operation
|
9
|
+
else
|
10
|
+
object
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
@@ -30,6 +30,19 @@
|
|
30
30
|
::Insights::API::Common::GraphQL::AssociationLoader.new(<%= klass_name.constantize %>, "<%= associations %>", args, graphql_options).load(obj)
|
31
31
|
}
|
32
32
|
end
|
33
|
+
|
34
|
+
field :<%= associations %>_aggregate do
|
35
|
+
description "Aggregation of <%= associations %> associated with <%= klass_name %> model."
|
36
|
+
type <%= "#{association_class_name}AggregateType" %>
|
37
|
+
|
38
|
+
associations_name = "<%= associations %>"
|
39
|
+
preload :<%= associations %>
|
40
|
+
|
41
|
+
resolve lambda { |obj, args, _ctx|
|
42
|
+
::Insights::API::Common::GraphQL::AssociationLoader.new(<%= klass_name.constantize %>, "<%= associations %>", args, graphql_options).load(obj)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
33
46
|
<% end %>
|
34
47
|
<% end %>
|
35
48
|
end
|
@@ -31,18 +31,9 @@ QueryType = ::GraphQL::ObjectType.define do
|
|
31
31
|
scope = model_class
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
openapi_doc = ::Insights::API::Common::OpenApi::Docs.instance["<%= api_version %>"]
|
36
|
-
openapi_schema_name, _schema = ::Insights::API::Common::GraphQL::Generator.openapi_schema(openapi_doc, klass_name)
|
37
|
-
association_attribute_properties =
|
38
|
-
Insights::API::Common::Filter.association_attribute_properties(openapi_doc.definitions, ActionController::Parameters.new(args[:filter]))
|
39
|
-
scope = ::Insights::API::Common::Filter.new(
|
40
|
-
scope,
|
41
|
-
ActionController::Parameters.new(args[:filter]),
|
42
|
-
openapi_doc.definitions[openapi_schema_name],
|
43
|
-
association_attribute_properties).apply
|
44
|
-
end
|
34
|
+
scope = ::Insights::API::Common::Filter.build_filtered_scope(scope, "<%= api_version %>", klass_name, args[:filter])
|
45
35
|
scope = ::Insights::API::Common::GraphQL.search_options(scope, args)
|
36
|
+
|
46
37
|
if <%= graphql_options[:use_pagination_v2] %> == true
|
47
38
|
::Insights::API::Common::PaginatedResponseV2.new(
|
48
39
|
base_query: scope, request: nil, limit: args[:limit], offset: args[:offset], sort_by: args[:sort_by]
|
@@ -54,5 +45,24 @@ QueryType = ::GraphQL::ObjectType.define do
|
|
54
45
|
end
|
55
46
|
}
|
56
47
|
end
|
48
|
+
|
49
|
+
field_aggregate = "#{collection}_aggregate"
|
50
|
+
field field_aggregate do
|
51
|
+
description "The #{collection} aggregation associated with this #{klass_name}"
|
52
|
+
klass_name_type = "::Insights::API::Common::GraphQL::Api::#{version_namespace}::#{klass_name}AggregateType".constantize
|
53
|
+
argument :filter, ::Insights::API::Common::GraphQL::Types::QueryFilter, "The Query Filter for querying the #{collection}"
|
54
|
+
|
55
|
+
type klass_name_type
|
56
|
+
|
57
|
+
resolve lambda { |_obj, args, _ctx|
|
58
|
+
if base_query.present?
|
59
|
+
scope = base_query.call(model_class, args, ctx)
|
60
|
+
else
|
61
|
+
scope = model_class
|
62
|
+
end
|
63
|
+
|
64
|
+
::Insights::API::Common::Filter.build_filtered_scope(scope, "<%= api_version %>", klass_name, args[:filter]).count
|
65
|
+
}
|
66
|
+
end
|
57
67
|
end
|
58
68
|
end
|
@@ -2,14 +2,27 @@ module Insights
|
|
2
2
|
module API
|
3
3
|
module Common
|
4
4
|
class Logging
|
5
|
-
def self.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
def self.logger_class
|
6
|
+
if ENV['LOG_HANDLER'] == "haberdasher"
|
7
|
+
"Insights::Loggers::StdErrorLogger"
|
8
|
+
else
|
9
|
+
"Insights::Loggers::CloudWatch"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.activate(config, app_name = nil)
|
14
|
+
require 'insights/loggers'
|
15
|
+
log_params = {}
|
16
|
+
klass_for_logger = if Rails.env.production?
|
17
|
+
config.colorize_logging = false
|
18
|
+
log_params[:app_name] = app_name if app_name
|
19
|
+
logger_class
|
20
|
+
else
|
21
|
+
log_params = {:log_path => Rails.root.join("log", "#{Rails.env}.log")}
|
22
|
+
"ManageIQ::Loggers::Base"
|
23
|
+
end
|
24
|
+
|
25
|
+
config.logger = Insights::Loggers::Factory.create_logger(klass_for_logger, log_params)
|
13
26
|
end
|
14
27
|
end
|
15
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insights-api-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Insights Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_tenant
|
@@ -73,33 +73,19 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 5.2.2.1
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: insights-loggers-ruby
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 0.1.10
|
82
82
|
type: :runtime
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: cloudwatchlogger
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 0.2.1
|
96
|
-
type: :runtime
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 0.2.1
|
88
|
+
version: 0.1.10
|
103
89
|
- !ruby/object:Gem::Dependency
|
104
90
|
name: prometheus_exporter
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -396,6 +382,8 @@ files:
|
|
396
382
|
- lib/insights/api/common/graphql/associated_records.rb
|
397
383
|
- lib/insights/api/common/graphql/association_loader.rb
|
398
384
|
- lib/insights/api/common/graphql/generator.rb
|
385
|
+
- lib/insights/api/common/graphql/templates/aggregate_model_type.erb
|
386
|
+
- lib/insights/api/common/graphql/templates/aggregate_type.erb
|
399
387
|
- lib/insights/api/common/graphql/templates/model_type.erb
|
400
388
|
- lib/insights/api/common/graphql/templates/query_type.erb
|
401
389
|
- lib/insights/api/common/graphql/templates/schema.erb
|
@@ -457,7 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
457
445
|
- !ruby/object:Gem::Version
|
458
446
|
version: '0'
|
459
447
|
requirements: []
|
460
|
-
rubygems_version: 3.0.3
|
448
|
+
rubygems_version: 3.0.3.1
|
461
449
|
signing_key:
|
462
450
|
specification_version: 4
|
463
451
|
summary: Common Utilites for Insights microservices
|