| `gitlab_banzai_cached_render_real_duration_seconds` | Histogram | 9.4 | Duration of rendering Markdown into HTML when cached output exists | `controller`, `action` |
| `gitlab_banzai_cached_render_real_duration_seconds` | Histogram | 9.4 | Duration of rendering Markdown into HTML when cached output exists | `controller`, `action` |
| `gitlab_banzai_cacheless_render_real_duration_seconds` | Histogram | 9.4 | Duration of rendering Markdown into HTML when cached output does not exist | `controller`, `action` |
| `gitlab_banzai_cacheless_render_real_duration_seconds` | Histogram | 9.4 | Duration of rendering Markdown into HTML when cached output does not exist | `controller`, `action` |
| `http_request_duration_seconds` | Histogram | 9.4 | HTTP response time from rack middleware | `method` |
| `http_request_duration_seconds` | Histogram | 9.4 | HTTP response time from rack middleware | `method` |
| `gitlab_transaction_db_count_total` | Counter | 13.1 | Counter for total number of SQL calls | `controller`, `action` |
| `gitlab_transaction_db_count_total` | Counter | 13.1 | Counter for total number of SQL calls | `controller`, `action` |
| `gitlab_transaction_db_<role>_count_total` | Counter | 13.10 | Counter for total number of SQL calls, grouped by database roles (primary/replica) | `controller`, `action` |
| `gitlab_transaction_db_write_count_total` | Counter | 13.1 | Counter for total number of write SQL calls | `controller`, `action` |
| `gitlab_transaction_db_write_count_total` | Counter | 13.1 | Counter for total number of write SQL calls | `controller`, `action` |
| `gitlab_transaction_db_cached_count_total` | Counter | 13.1 | Counter for total number of cached SQL calls | `controller`, `action` |
| `gitlab_transaction_db_cached_count_total` | Counter | 13.1 | Counter for total number of cached SQL calls | `controller`, `action` |
| `gitlab_transaction_db_<role>_cached_count_total` | Counter | 13.1 | Counter for total number of cached SQL calls, grouped by database roles (primary/replica) | `controller`, `action` |
| `http_elasticsearch_requests_duration_seconds`**(PREMIUM)** | Histogram | 13.1 | Elasticsearch requests duration during web transactions | `controller`, `action` |
| `http_elasticsearch_requests_duration_seconds`**(PREMIUM)** | Histogram | 13.1 | Elasticsearch requests duration during web transactions | `controller`, `action` |
| `http_elasticsearch_requests_total`**(PREMIUM)** | Counter | 13.1 | Elasticsearch requests count during web transactions | `controller`, `action` |
| `http_elasticsearch_requests_total`**(PREMIUM)** | Counter | 13.1 | Elasticsearch requests count during web transactions | `controller`, `action` |
| `pipelines_created_total` | Counter | 9.4 | Counter of pipelines created | |
| `pipelines_created_total` | Counter | 9.4 | Counter of pipelines created | |
'SQL'|'SELECT * FROM users WHERE id = 10'|true|false|false
'SQL'|'WITH active_milestones AS (SELECT COUNT(*), state FROM milestones GROUP BY state) SELECT * FROM active_milestones'|true|false|false
'SQL'|'SELECT * FROM users WHERE id = 10 FOR UPDATE'|true|true|false
'SQL'|'WITH archived_rows AS (SELECT * FROM users WHERE archived = true) INSERT INTO products_log SELECT * FROM archived_rows'|true|true|false
'SQL'|'DELETE FROM users where id = 10'|true|true|false
'SQL'|'INSERT INTO project_ci_cd_settings (project_id) SELECT id FROM projects'|true|true|false
'SQL'|'UPDATE users SET admin = true WHERE id = 10'|true|true|false
'CACHE'|'SELECT * FROM users WHERE id = 10'|true|false|true
'SCHEMA'|"SELECT attr.attname FROM pg_attribute attr INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = any(cons.conkey) WHERE cons.contype = 'p' AND cons.conrelid = '\"projects\"'::regclass"|false|false|false
'SCHEMA'|"SELECT attr.attname FROM pg_attribute attr INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = any(cons.conkey) WHERE cons.contype = 'p' AND cons.conrelid = '\"projects\"'::regclass"|false|false|false
it_behaves_like'store ActiveRecord info in RequestStore'
{
db_count: 1,
db_write_count: 0,
db_cached_count: 0
}
end
it_behaves_like'track query in metrics'
it_behaves_like'track query in RequestStore'
context'with only select'do
let(:payload){{sql: sql('WITH active_milestones AS (SELECT COUNT(*), state FROM milestones GROUP BY state) SELECT * FROM active_milestones',comments: comments)}}
it_behaves_like'track query in metrics'
it_behaves_like'track query in RequestStore'
end
end
shared_examples'write queries'do
let(:expected_counters)do
{
db_count: 1,
db_write_count: 1,
db_cached_count: 0
}
end
end
context'with select for update sql event'do
describe'without a current transaction'do
let(:payload){{sql: sql('SELECT * FROM users WHERE id = 10 FOR UPDATE',comments: comments)}}
let(:payload){{sql: sql('WITH archived_rows AS (SELECT * FROM users WHERE archived = true) INSERT INTO products_log SELECT * FROM archived_rows',comments: comments)}}
it_behaves_like'track query in metrics'
it_behaves_like'track query in RequestStore'
end
end
context'with delete sql event'do
let(:payload){{sql: sql('DELETE FROM users where id = 10',comments: comments)}}
it_behaves_like'track query in metrics'
it_behaves_like'track query in RequestStore'
end
end
context'with insert sql event'do
it_behaves_like'store ActiveRecord info in RequestStore'
let(:payload){{sql: sql('INSERT INTO project_ci_cd_settings (project_id) SELECT id FROM projects',comments: comments)}}
it_behaves_like'track query in metrics'
it_behaves_like'track query in RequestStore'
end
end
context'with update sql event'do
let(:payload){{sql: sql('UPDATE users SET admin = true WHERE id = 10',comments: comments)}}
it_behaves_like'track query in metrics'
it_behaves_like'track query in RequestStore'
end
end
end
end
context'without Marginalia comments'do
context'without Marginalia comments'do
let(:comments){false}
let(:comments){false}
it_behaves_like'write queries'
it_behaves_like'track generic sql events'
it_behaves_like'read queries'
end
end
context'with Marginalia comments'do
context'with Marginalia comments'do
let(:comments){true}
let(:comments){true}
it_behaves_like'write queries'
it_behaves_like'track generic sql events'
it_behaves_like'read queries'
end
context'with cached query'do
let(:expected_counters)do
{
db_count: 1,
db_write_count: 0,
db_cached_count: 1
}
end
context'with cached payload 'do
let(:payload)do
{
sql: sql('SELECT * FROM users WHERE id = 10'),
cached: true
}
end
it_behaves_like'track query in metrics'
it_behaves_like'track query in RequestStore'
end
context'with cached payload name'do
let(:payload)do
{
sql: sql('SELECT * FROM users WHERE id = 10'),
name: 'CACHE'
}
end
it_behaves_like'track query in metrics'
it_behaves_like'track query in RequestStore'
end
end
context'events are internal to Rails or irrelevant'do
let(:schema_event)do
double(
:event,
name: 'sql.active_record',
payload: {
sql: sql("SELECT attr.attname FROM pg_attribute attr INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = any(cons.conkey) WHERE cons.contype = 'p' AND cons.conrelid = '\"projects\"'::regclass"),
name: 'SCHEMA',
connection_id: 135,
statement_name: nil,
binds: []
},
duration: 0.7
)
end
let(:begin_event)do
double(
:event,
name: 'sql.active_record',
payload: {
sql: "BEGIN",
name: nil,
connection_id: 231,
statement_name: nil,
binds: []
},
duration: 1.1
)
end
let(:commit_event)do
double(
:event,
name: 'sql.active_record',
payload: {
sql: "COMMIT",
name: nil,
connection_id: 212,
statement_name: nil,
binds: []
},
duration: 1.6
)
end
it'skips schema/begin/commit sql commands'do
allow(subscriber).toreceive(:current_transaction)
.at_least(:once)
.and_return(transaction)
expect(transaction).not_toreceive(:increment)
subscriber.sql(schema_event)
subscriber.sql(begin_event)
subscriber.sql(commit_event)
end
end
end
end
describe'self.db_counter_payload'do
beforedo
allow(subscriber).toreceive(:current_transaction)
.at_least(:once)
.and_return(transaction)
end
context'when RequestStore is enabled',:request_storedo