• Dylan Griffith's avatar
    Change to db_config.name for logging metrics per database · 805e4096
    Dylan Griffith authored
    As GitLab is planning on moving `ci_*` tables to a separate database we
    need to start expanding our observability/logging/metrics to allow us to
    distinguish between the different databases being queried.
    
    We had already implemented logging per database by including the
    database name (ie. what Postgres calls the database) in the log
    statements in
    https://gitlab.com/gitlab-org/gitlab/-/merge_requests/63490 but later we
    learnt this wasn't a good idea because we may want to use 2 different
    Postgres servers with the same Database name (in fact that's what our
    current migration plan involves). As such we need to use the name that
    the GitLab application uses to distinguish between the 2 different
    databases. This is the name used to configure the `config/database.yml`
    and must be unique.
    
    In the default case it does not have a name and Rails will call it
    `primary`. This has the unfortunate result that this MR will add JSON
    log keys `db_replica_primary_duration_s` and
    `db_primary_primary_duration_s` because we already use the words
    `primary/replica` to distinguish between our read-write primary and
    read-only replicas. We plan to eventually force the
    `config/database.yml` to name these `main` and `ci` and at that time
    these log statements will be a little clearer. In the meantime this is
    behind a feature flag so should not bother people that aren't intending
    to try and make sense of these metrics.
    805e4096
structured_logger_spec.rb 15.6 KB