Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • omnibus-gitlab omnibus-gitlab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 1,059
    • Issues 1,059
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 53
    • Merge requests 53
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Code review
    • Insights
    • Issue
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • omnibus-gitlabomnibus-gitlab
  • Issues
  • #6587
Closed
Open
Issue created Dec 16, 2021 by Grant Young@grantyoungDeveloper

Consul is unable to watch additional Postgres services and perform failover due to hardcodes

While building out a new environment where there's two HA Postgres setups for GitLab and Praefect respectively it was found that Consul is unable to watch the latter due to some hardcodes.

This only applies to the Watch side of Consul on PgBouncer nodes where the Watcher as well as it's script are hardcoded to a service named postgresql specifically:

/var/opt/gitlab/consul/scripts/failover_pgbouncer

63  masters = find_masters(healthy_agents, 'service:postgresql')

On this line the service being looked for by the script is hardcoded to postgresql. This should be configurable by a omnibus setting

/var/opt/gitlab/consul/config.d/watcher_postgresql.json

The generated file for the Consul Watcher is hardcoded to only follow a service that has the same name as the watcher, e.g. postgresql:

{
  "watches": [
    {
      "type": "service",
      "service": "postgresql",
      "args": [
        "/var/opt/gitlab/consul/scripts/failover_pgbouncer"
      ]
    }
  ]
}

The service name here should be overridable like we can do on the service side with consul['internal']['postgresql_service_name']

gitlab-ctl-commands-ee/lib/pgbouncer.rb

     @database = if attributes.key?('gitlab')
                    attributes['gitlab']['gitlab-rails']['db_database']
                  else
                    'gitlabhq_production'
                  end

[...]

    def database_paused?
      return false unless running?

      databases = show_databases

      # In `show databases` output, column 10 gives paused status of database
      # (1 for paused and 0 for unpaused)
      paused_status = databases.lines.find { |x| x.match(/#{@database}/) }.split('|')[10].strip

      paused_status == "1"
    end

    def resume_if_paused
      pgbouncer_command("RESUME #{@database}") if database_paused?
    end
Edited Dec 17, 2021 by Grant Young
Assignee
Assign to
Time tracking