mirror of
https://github.com/mozilla-services/syncstorage-rs.git
synced 2026-05-17 02:26:54 +02:00
Some checks failed
Glean probe-scraper / glean-probe-scraper (push) Has been cancelled
Main Workflow - Lint, Build, Test / python-env (push) Has been cancelled
Main Workflow - Lint, Build, Test / rust-env (push) Has been cancelled
Main Workflow - Lint, Build, Test / python-checks (push) Has been cancelled
Main Workflow - Lint, Build, Test / rust-checks (push) Has been cancelled
Main Workflow - Lint, Build, Test / clippy (mysql) (push) Has been cancelled
Main Workflow - Lint, Build, Test / clippy (postgres) (push) Has been cancelled
Main Workflow - Lint, Build, Test / clippy (spanner) (push) Has been cancelled
Main Workflow - Lint, Build, Test / build-and-unit-test-postgres (push) Has been cancelled
Main Workflow - Lint, Build, Test / build-postgres-image (push) Has been cancelled
Main Workflow - Lint, Build, Test / postgres-e2e-tests (push) Has been cancelled
Main Workflow - Lint, Build, Test / build-and-unit-test-mysql (push) Has been cancelled
Main Workflow - Lint, Build, Test / build-mysql-image (push) Has been cancelled
Main Workflow - Lint, Build, Test / mysql-e2e-tests (push) Has been cancelled
Main Workflow - Lint, Build, Test / build-and-unit-test-spanner (push) Has been cancelled
Main Workflow - Lint, Build, Test / build-spanner-image (push) Has been cancelled
Main Workflow - Lint, Build, Test / spanner-e2e-tests (push) Has been cancelled
Build, Tag and Push Container Images to GAR / check (push) Has been cancelled
Build, Tag and Push Container Images to GAR / build-and-push-syncstorage-rs (push) Has been cancelled
Build, Tag and Push Container Images to GAR / build-and-push-syncserver-postgres (push) Has been cancelled
Build, Tag and Push Container Images to GAR / build-and-push-syncstorage-rs-spanner-python-utils (push) Has been cancelled
Build, Tag and Push Container Images to GAR / build-and-push-syncserver-postgres-python-utils (push) Has been cancelled
Build, Tag and Push Container Images to GAR / build-and-push-syncserver-mysql (push) Has been cancelled
Publish Sync docs to pages / build-mdbook (push) Has been cancelled
Publish Sync docs to pages / build-openapi (push) Has been cancelled
Publish Sync docs to pages / combine-and-prepare (push) Has been cancelled
Publish Sync docs to pages / deploy (push) Has been cancelled
feat: add python utils and integrate into workflow
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
# Count the number of users in the spanner database
|
|
# Specifically, the number of unique fxa_uid found in the user_collections table
|
|
#
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
"""Count distinct users in the Spanner database."""
|
|
|
|
import sys
|
|
import logging
|
|
from statsd.defaults.env import statsd
|
|
|
|
from google.cloud import spanner
|
|
from utils import ids_from_env
|
|
|
|
# set up logger
|
|
logging.basicConfig(
|
|
format='{"datetime": "%(asctime)s", "message": "%(message)s"}',
|
|
stream=sys.stdout,
|
|
level=logging.INFO,
|
|
)
|
|
|
|
# Change these to match your install.
|
|
client = spanner.Client()
|
|
|
|
|
|
def spanner_read_data() -> None:
|
|
"""Read data from Spanner to count the number of distinct users.
|
|
|
|
Connect to a Spanner instance and database using environment variables,
|
|
execute a SQL query to count distinct `fxa_uid` entries in the
|
|
`user_collections` table, and log the result with statsd metrics.
|
|
|
|
Args:
|
|
None
|
|
|
|
Returns:
|
|
None
|
|
"""
|
|
(instance_id, database_id, project_id) = ids_from_env()
|
|
instance = client.instance(instance_id)
|
|
database = instance.database(database_id)
|
|
project = instance.database(database_id)
|
|
|
|
logging.info(f"For {instance_id}:{database_id} {project}")
|
|
|
|
# Count users
|
|
with statsd.timer("syncstorage.count_users.duration"):
|
|
with database.snapshot() as snapshot:
|
|
query = "SELECT COUNT (DISTINCT fxa_uid) FROM user_collections"
|
|
result = snapshot.execute_sql(query)
|
|
user_count = result.one()[0]
|
|
statsd.gauge("syncstorage.distinct_fxa_uid", user_count)
|
|
logging.info(f"Count found {user_count} distinct users")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logging.info("Starting count_users.py")
|
|
|
|
spanner_read_data()
|
|
|
|
logging.info("Completed count_users.py")
|