pghero 2.7.2 → 2.7.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pghero might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fe5afd370afcf20d24e1b4e7176931f32671a1cf36866c38c5b88796fab342a
4
- data.tar.gz: 20fb8e6756163e7125e5373f8397cfec8c501c5914e610fa23a2ae77c78a6778
3
+ metadata.gz: cde64b8247e49038ddc1eb136a9900386b128f8e2145e60eb201bec3be586470
4
+ data.tar.gz: e09c2d6705c5d5edb4054c8a5df8b41847c66e9dfc5ba04d7705c1f9cbb4eb56
5
5
  SHA512:
6
- metadata.gz: cd9d194ae73f51a58880badd3e3b615c19bfc3390001ccd04d3d69878d0374e124c49acf8281714099ea60258ffdda6142d7ac993134b705216d408e274655b6
7
- data.tar.gz: 418f6a52003f27819d23e15e7f8d20e70119d6ca7f40fdff751dcea2cddf810c104599a483bd84c42eb493e12dcf0aa04a0073b5001b750626b605a8d163c6c0
6
+ metadata.gz: 8a56fb48768e6dfbe10c1056dc71f32e339fa63dba628fcb76fec5cc1c2ca3867be45e6468b06f9fc8ae79da3fab09f8de8c1ad08d4f550c3de5db96e16cd67f
7
+ data.tar.gz: b5dc376105034625527ff19fa07c21bbf0ffe2281577f3fec3ebd39742c2560b8ea5de33e5e5abe9af078a131efe06e855c18cea733583b3314a0de9422e041b
@@ -1,3 +1,7 @@
1
+ ## 2.7.3 (2020-11-23)
2
+
3
+ - Improved index suggestions when hash, GiST, GIN, or BRIN index present
4
+
1
5
  ## 2.7.2 (2020-09-10)
2
6
 
3
7
  - Fixed error with historical query stats
data/README.md CHANGED
@@ -8,7 +8,7 @@ A performance dashboard for Postgres
8
8
 
9
9
  :tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
10
10
 
11
- [![Build Status](https://travis-ci.org/ankane/pghero.svg?branch=master)](https://travis-ci.org/ankane/pghero) [![Docker Pulls](https://img.shields.io/docker/pulls/ankane/pghero)](https://hub.docker.com/repository/docker/ankane/pghero)
11
+ [![Build Status](https://github.com/ankane/pghero/workflows/build/badge.svg?branch=master)](https://github.com/ankane/pghero/actions) [![Docker Pulls](https://img.shields.io/docker/pulls/ankane/pghero)](https://hub.docker.com/repository/docker/ankane/pghero)
12
12
 
13
13
  ## Installation
14
14
 
@@ -113,13 +113,13 @@ module PgHero
113
113
 
114
114
  if !ENV["PGHERO_DATABASE_URL"] && spec_supported?
115
115
  ActiveRecord::Base.configurations.configs_for(env_name: env, include_replicas: true).each do |db|
116
- databases[db.spec_name] = {"spec" => db.spec_name}
116
+ databases[db.send(spec_name_key)] = {"spec" => db.send(spec_name_key)}
117
117
  end
118
118
  end
119
119
 
120
120
  if databases.empty?
121
121
  databases["primary"] = {
122
- "url" => ENV["PGHERO_DATABASE_URL"] || ActiveRecord::Base.connection_config
122
+ "url" => ENV["PGHERO_DATABASE_URL"] || connection_config(ActiveRecord::Base)
123
123
  }
124
124
  end
125
125
 
@@ -211,6 +211,18 @@ module PgHero
211
211
  ActiveRecord::VERSION::MAJOR >= 6
212
212
  end
213
213
 
214
+ # private
215
+ def connection_config(model)
216
+ ActiveRecord::VERSION::STRING.to_f >= 6.1 ? model.connection_db_config.configuration_hash : model.connection_config
217
+ end
218
+
219
+ # private
220
+ # Rails 6.1 deprecate `spec_name` and use `name` for configurations
221
+ # https://github.com/rails/rails/pull/38536
222
+ def spec_name_key
223
+ ActiveRecord::VERSION::STRING.to_f >= 6.1 ? :name : :spec_name
224
+ end
225
+
214
226
  private
215
227
 
216
228
  def each_database
@@ -149,11 +149,14 @@ module PgHero
149
149
  # resolve spec
150
150
  if !url && config["spec"]
151
151
  raise Error, "Spec requires Rails 6+" unless PgHero.spec_supported?
152
- resolved = ActiveRecord::Base.configurations.configs_for(env_name: PgHero.env, spec_name: config["spec"], include_replicas: true)
152
+ config_options = {env_name: PgHero.env, PgHero.spec_name_key => config["spec"], include_replicas: true}
153
+ resolved = ActiveRecord::Base.configurations.configs_for(**config_options)
153
154
  raise Error, "Spec not found: #{config["spec"]}" unless resolved
154
- url = resolved.config
155
+ url = ActiveRecord::VERSION::STRING.to_f >= 6.1 ? resolved.configuration_hash : resolved.config
155
156
  end
156
157
 
158
+ url = url.dup
159
+
157
160
  Class.new(PgHero::Connection) do
158
161
  def self.name
159
162
  "PgHero::Connection::Database#{object_id}"
@@ -30,7 +30,23 @@ module PgHero
30
30
  if best_index[:found]
31
31
  index = best_index[:index]
32
32
  best_index[:table_indexes] = indexes_by_table[index[:table]].to_a
33
- covering_index = existing_columns[index[:using] || "btree"][index[:table]].find { |e| index_covers?(e, index[:columns]) }
33
+
34
+ # indexes of same type
35
+ indexes = existing_columns[index[:using] || "btree"][index[:table]]
36
+
37
+ if best_index[:structure][:sort].empty?
38
+ # gist indexes without an opclass
39
+ # (opclass is part of column name, so columns won't match if opclass present)
40
+ indexes += existing_columns["gist"][index[:table]]
41
+
42
+ # hash indexes work for equality
43
+ indexes += existing_columns["hash"][index[:table]] if best_index[:structure][:where].all? { |v| v[:op] == "=" }
44
+
45
+ # brin indexes work for all
46
+ indexes += existing_columns["brin"][index[:table]]
47
+ end
48
+
49
+ covering_index = indexes.find { |e| index_covers?(e.map { |v| v.sub(/ inet_ops\z/, "") }, index[:columns]) }
34
50
  if covering_index
35
51
  best_index[:covering_index] = covering_index
36
52
  best_index[:explanation] = "Covered by index on (#{covering_index.join(", ")})"
@@ -86,7 +102,7 @@ module PgHero
86
102
  # get stats about columns for relevant tables
87
103
  tables = parts.values.map { |t| t[:table] }.uniq
88
104
  # TODO get schema from query structure, then try search path
89
- schema = connection_model.connection_config[:schema] || "public"
105
+ schema = PgHero.connection_config(connection_model)[:schema] || "public"
90
106
  if tables.any?
91
107
  row_stats = Hash[table_stats(table: tables, schema: schema).map { |i| [i[:table], i[:estimated_rows]] }]
92
108
  col_stats = column_stats(table: tables, schema: schema).group_by { |i| i[:table] }
@@ -144,7 +144,7 @@ module PgHero
144
144
 
145
145
  # validate input since we need to interpolate below
146
146
  raise Error, "Invalid metric name" unless metric_name =~ /\A[a-z\/_]+\z/i
147
- raise Error, "Invalid database id" unless gcp_database_id =~ /\A[a-z\-:]+\z/i
147
+ raise Error, "Invalid database id" unless gcp_database_id =~ /\A[a-z0-9\-:]+\z/i
148
148
 
149
149
  # we handle three situations:
150
150
  # 1. google-cloud-monitoring-v3
@@ -5,7 +5,7 @@ module PgHero
5
5
  # TODO quote in 3.0, but still not officially supported
6
6
  def create_user(user, password: nil, schema: "public", database: nil, readonly: false, tables: nil)
7
7
  password ||= random_password
8
- database ||= connection_model.connection_config[:database]
8
+ database ||= PgHero.connection_config(connection_model)[:database]
9
9
 
10
10
  commands =
11
11
  [
@@ -44,7 +44,7 @@ module PgHero
44
44
  # documented as unsafe to pass user input
45
45
  # TODO quote in 3.0, but still not officially supported
46
46
  def drop_user(user, schema: "public", database: nil)
47
- database ||= connection_model.connection_config[:database]
47
+ database ||= PgHero.connection_config(connection_model)[:database]
48
48
 
49
49
  # thanks shiftb
50
50
  commands =
@@ -1,3 +1,3 @@
1
1
  module PgHero
2
- VERSION = "2.7.2"
2
+ VERSION = "2.7.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pghero
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-10 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,91 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5'
27
- - !ruby/object:Gem::Dependency
28
- name: activerecord-import
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pg
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: pg_query
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- description:
27
+ description:
112
28
  email: andrew@chartkick.com
113
29
  executables: []
114
30
  extensions: []
@@ -191,7 +107,7 @@ homepage: https://github.com/ankane/pghero
191
107
  licenses:
192
108
  - MIT
193
109
  metadata: {}
194
- post_install_message:
110
+ post_install_message:
195
111
  rdoc_options: []
196
112
  require_paths:
197
113
  - lib
@@ -206,8 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
122
  - !ruby/object:Gem::Version
207
123
  version: '0'
208
124
  requirements: []
209
- rubygems_version: 3.1.2
210
- signing_key:
125
+ rubygems_version: 3.1.4
126
+ signing_key:
211
127
  specification_version: 4
212
128
  summary: A performance dashboard for Postgres
213
129
  test_files: []