Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report the number of times a feature is used as a metric #8342

Merged
merged 2 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions edb/server/compiler/ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ def produce_feature_used_metrics(
features: dict[str, float] = {}

def _track(key: str) -> None:
features[key] = 1
features[key] = features.get(key, 0) + 1

# TODO(perf): Should we optimize peeking into the innards directly
# so we can skip creating the proxies?
Expand Down Expand Up @@ -1408,7 +1408,7 @@ def administer_repair_schema(
user_schema=current_tx.get_user_schema_if_updated(),
global_schema=current_tx.get_global_schema_if_updated(),
config_ops=config_ops,
feature_used_metrics={},
feature_used_metrics=None,
)


Expand Down
19 changes: 17 additions & 2 deletions edb/server/dbview/dbview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,20 @@ cdef class Database:
tname = self.tenant.get_instance_name()
keys = self._feature_used_metrics.keys() | feature_used_metrics.keys()
for key in keys:
# Update the count of how many times the feature is used
metrics.feature_used.inc(
feature_used_metrics.get(key, 0.0)
- self._feature_used_metrics.get(key, 0.0),
tname,
key,
)
# Update the count of branches using the feature at all
metrics.feature_used_branches.inc(
(feature_used_metrics.get(key, 0.0) > 0)
- (self._feature_used_metrics.get(key, 0.0) > 0),
tname,
key,
)

self._feature_used_metrics = feature_used_metrics

Expand Down Expand Up @@ -1873,9 +1881,16 @@ cdef class DatabaseIndex:
cdef inline set_current_branches(self):
metrics.current_branches.set(
sum(
1
dbname != defines.EDGEDB_SYSTEM_DB
for dbname in self._dbs
if dbname != defines.EDGEDB_SYSTEM_DB
),
self._tenant.get_instance_name(),
)
metrics.current_introspected_branches.set(
sum(
dbname != defines.EDGEDB_SYSTEM_DB
and db.user_schema_pickle is not None
for dbname, db in self._dbs.items()
),
self._tenant.get_instance_name(),
)
Expand Down
13 changes: 12 additions & 1 deletion edb/server/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
labels=('tenant',),
)

current_introspected_branches = registry.new_labeled_gauge(
'branches_introspected_current',
'Current number of branches whose schemas are introspected.',
labels=('tenant',),
)

total_backend_connections = registry.new_labeled_counter(
'backend_connections_total',
'Total number of backend connections established.',
Expand Down Expand Up @@ -211,11 +217,16 @@
labels=('tenant', 'extension'),
)

feature_used = registry.new_labeled_gauge(
feature_used_branches = registry.new_labeled_gauge(
'feature_used_branch_count_current',
'How many branches a schema feature is used by.',
labels=('tenant', 'feature'),
)
feature_used = registry.new_labeled_gauge(
'feature_used_num_count_current',
'How many times a schema feature is used.',
labels=('tenant', 'feature'),
)

auth_successful_logins = registry.new_labeled_counter(
"auth_successful_logins_total",
Expand Down