gitlab-exporter 16.2.0 → 16.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/gitlab_exporter/database/zoekt.rb +40 -8
- data/lib/gitlab_exporter/version.rb +1 -1
- data/spec/database/zoekt_spec.rb +9 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f525375bfd6495a98af906badecaa459b07d6464327b47abd754e9a54b002522
         | 
| 4 | 
            +
              data.tar.gz: 13388a0735f269ed0ad9c43a324e8e77a4c008ac2f8d9ec9a10a48a623886141
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0e754a5a16e88b93604313e719ae13441ffad1c4062d531c375aa11d7747a2aa4235037a42665d318b7534c3d6568ccc1f0c4fd8321cbed5fde3333e4a81bbbb
         | 
| 7 | 
            +
              data.tar.gz: 230d9ac1d8925987027961bde296501e3dd665082f7f8140c29582997249f0342a721b58b5ad351e2c204c16afac46bdc1ee8ceed9095533a8614c7ad0f250b2
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                gitlab-exporter (16. | 
| 4 | 
            +
                gitlab-exporter (16.3.0)
         | 
| 5 5 | 
             
                  connection_pool (= 2.5.4)
         | 
| 6 6 | 
             
                  deep_merge (~> 1.2.2)
         | 
| 7 7 | 
             
                  faraday (= 2.14.0)
         | 
| @@ -66,7 +66,7 @@ GEM | |
| 66 66 | 
             
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 67 67 | 
             
                  rspec-support (~> 3.12.0)
         | 
| 68 68 | 
             
                rspec-support (3.12.0)
         | 
| 69 | 
            -
                rubocop (1.81. | 
| 69 | 
            +
                rubocop (1.81.6)
         | 
| 70 70 | 
             
                  json (~> 2.3)
         | 
| 71 71 | 
             
                  language_server-protocol (~> 3.17.0.2)
         | 
| 72 72 | 
             
                  lint_roller (~> 1.1.0)
         | 
| @@ -31,6 +31,16 @@ module GitLab | |
| 31 31 | 
             
                      SELECT schema_version, id FROM zoekt_nodes
         | 
| 32 32 | 
             
                    SQL
         | 
| 33 33 |  | 
| 34 | 
            +
                    ZOEKT_NODES_STATUS_QUERY = <<~SQL.freeze
         | 
| 35 | 
            +
                      SELECT
         | 
| 36 | 
            +
                        id,
         | 
| 37 | 
            +
                        CASE
         | 
| 38 | 
            +
                          WHEN last_seen_at < NOW() - INTERVAL '2 minute' THEN 0
         | 
| 39 | 
            +
                          ELSE 1
         | 
| 40 | 
            +
                        END AS status
         | 
| 41 | 
            +
                      FROM zoekt_nodes;
         | 
| 42 | 
            +
                    SQL
         | 
| 43 | 
            +
             | 
| 34 44 | 
             
                    ZOEKT_REPOSITORY_SCHEMA_VERSION_QUERY = <<~SQL.freeze
         | 
| 35 45 | 
             
                      SELECT
         | 
| 36 46 | 
             
                        COUNT(*)
         | 
| @@ -58,7 +68,8 @@ module GitLab | |
| 58 68 |  | 
| 59 69 | 
             
                      {
         | 
| 60 70 | 
             
                        task_processing_query_result: execute(ZOEKT_TASKS_PROCESSING_QUERY, [Time.now.utc]),
         | 
| 61 | 
            -
                        repositories_schema_version_query_result: repositories_schema_version_query_result
         | 
| 71 | 
            +
                        repositories_schema_version_query_result: repositories_schema_version_query_result,
         | 
| 72 | 
            +
                        zoekt_nodes_status_query_result: execute(ZOEKT_NODES_STATUS_QUERY)
         | 
| 62 73 | 
             
                      }.compact
         | 
| 63 74 | 
             
                    end
         | 
| 64 75 |  | 
| @@ -119,13 +130,23 @@ module GitLab | |
| 119 130 |  | 
| 120 131 | 
             
                  # The prober which is called when gathering metrics
         | 
| 121 132 | 
             
                  class ZoektProber
         | 
| 122 | 
            -
                    PrometheusMetrics.describe( | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
                     | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 133 | 
            +
                    PrometheusMetrics.describe(
         | 
| 134 | 
            +
                      "search_zoekt_task_processing_queue_size",
         | 
| 135 | 
            +
                      "Number of tasks waiting to be processed by Zoekt",
         | 
| 136 | 
            +
                      "gauge"
         | 
| 137 | 
            +
                    )
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                    PrometheusMetrics.describe(
         | 
| 140 | 
            +
                      "search_zoekt_repositories_schema_version_count",
         | 
| 141 | 
            +
                      "Number of zoekt_repositories which do not have the latest schema version",
         | 
| 142 | 
            +
                      "gauge"
         | 
| 143 | 
            +
                    )
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                    PrometheusMetrics.describe(
         | 
| 146 | 
            +
                      "search_zoekt_nodes_status",
         | 
| 147 | 
            +
                      "Status of each zoekt_node. 0 is offline (last seen more than 2 minutes ago), 1 is online",
         | 
| 148 | 
            +
                      "gauge"
         | 
| 149 | 
            +
                    )
         | 
| 129 150 |  | 
| 130 151 | 
             
                    def initialize(metrics: PrometheusMetrics.new, **opts)
         | 
| 131 152 | 
             
                      @metrics = metrics
         | 
| @@ -140,6 +161,9 @@ module GitLab | |
| 140 161 | 
             
                      results[:repositories_schema_version_query_result]&.each do |row|
         | 
| 141 162 | 
             
                        add_zoekt_repositories_by_schema_version_to_metric(row)
         | 
| 142 163 | 
             
                      end
         | 
| 164 | 
            +
                      results[:zoekt_nodes_status_query_result]&.each do |row|
         | 
| 165 | 
            +
                        add_zoekt_nodes_status_to_metric(row)
         | 
| 166 | 
            +
                      end
         | 
| 143 167 |  | 
| 144 168 | 
             
                      self
         | 
| 145 169 | 
             
                    rescue PG::ConnectionBad
         | 
| @@ -164,6 +188,14 @@ module GitLab | |
| 164 188 | 
             
                      )
         | 
| 165 189 | 
             
                    end
         | 
| 166 190 |  | 
| 191 | 
            +
                    def add_zoekt_nodes_status_to_metric(row)
         | 
| 192 | 
            +
                      @metrics.add(
         | 
| 193 | 
            +
                        "search_zoekt_nodes_status",
         | 
| 194 | 
            +
                        row["status"].to_i,
         | 
| 195 | 
            +
                        zoekt_node_id: row["id"]
         | 
| 196 | 
            +
                      )
         | 
| 197 | 
            +
                    end
         | 
| 198 | 
            +
             | 
| 167 199 | 
             
                    def write_to(target)
         | 
| 168 200 | 
             
                      target.write(@metrics.to_s)
         | 
| 169 201 | 
             
                    end
         | 
    
        data/spec/database/zoekt_spec.rb
    CHANGED
    
    | @@ -9,6 +9,8 @@ describe GitLab::Exporter::Database::ZoektCollector do | |
| 9 9 | 
             
              let(:zoekt_nodes_query_results) { [{ "id" => "1", "schema_version" => "2302" }] }
         | 
| 10 10 | 
             
              let(:zoekt_enabled_query) { described_class::ZOEKT_ENABLED_QUERY }
         | 
| 11 11 | 
             
              let(:zoekt_repository_schema_version_query) { described_class::ZOEKT_REPOSITORY_SCHEMA_VERSION_QUERY }
         | 
| 12 | 
            +
              let(:zoekt_nodes_status_query) { described_class::ZOEKT_NODES_STATUS_QUERY }
         | 
| 13 | 
            +
              let(:zoekt_nodes_status_query_results) { [{ "id" => "1", "status" => "1" }] }
         | 
| 12 14 |  | 
| 13 15 | 
             
              let(:zoekt_repository_schema_version_query_results) { [{ "count" => "1" }] }
         | 
| 14 16 |  | 
| @@ -45,7 +47,8 @@ describe GitLab::Exporter::Database::ZoektCollector do | |
| 45 47 | 
             
                let(:result) do
         | 
| 46 48 | 
             
                  {
         | 
| 47 49 | 
             
                    repositories_schema_version_query_result: zoekt_repositories_schema_version_query_results,
         | 
| 48 | 
            -
                    task_processing_query_result: zoekt_tasks_processing_query_results
         | 
| 50 | 
            +
                    task_processing_query_result: zoekt_tasks_processing_query_results,
         | 
| 51 | 
            +
                    zoekt_nodes_status_query_result: zoekt_nodes_status_query_results
         | 
| 49 52 | 
             
                  }
         | 
| 50 53 | 
             
                end
         | 
| 51 54 |  | 
| @@ -75,6 +78,8 @@ describe GitLab::Exporter::Database::ZoektCollector do | |
| 75 78 | 
             
                                                               .and_return(zoekt_nodes_query_results)
         | 
| 76 79 | 
             
                    expect(connection).to receive(:exec_params).with(zoekt_repository_schema_version_query, %w[1 2302])
         | 
| 77 80 | 
             
                                                               .and_return(zoekt_repository_schema_version_query_results)
         | 
| 81 | 
            +
                    expect(connection).to receive(:exec_params).with(zoekt_nodes_status_query, [])
         | 
| 82 | 
            +
                                                               .and_return(zoekt_nodes_status_query_results)
         | 
| 78 83 |  | 
| 79 84 | 
             
                    expect(collector.run).to eq(result)
         | 
| 80 85 | 
             
                  end
         | 
| @@ -85,6 +90,8 @@ describe GitLab::Exporter::Database::ZoektCollector do | |
| 85 90 | 
             
                                                                .and_raise(PG::UndefinedTable)
         | 
| 86 91 | 
             
                      allow(connection).to receive(:exec_params).with(zoekt_nodes_query, [])
         | 
| 87 92 | 
             
                                                                .and_raise(PG::UndefinedTable)
         | 
| 93 | 
            +
                      allow(connection).to receive(:exec_params).with(zoekt_nodes_status_query, [])
         | 
| 94 | 
            +
                                                                .and_raise(PG::UndefinedTable)
         | 
| 88 95 |  | 
| 89 96 | 
             
                      expect(collector.run).to eq({})
         | 
| 90 97 | 
             
                    end
         | 
| @@ -98,6 +105,7 @@ describe GitLab::Exporter::Database::ZoektCollector do | |
| 98 105 | 
             
                                                                 .and_return(zoekt_nodes_query_results)
         | 
| 99 106 | 
             
                      expect(connection).to receive(:exec_params).with(zoekt_repository_schema_version_query, %w[1 2302])
         | 
| 100 107 | 
             
                                                                 .and_raise(PG::UndefinedTable)
         | 
| 108 | 
            +
                      expect(connection).to receive(:exec_params).with(zoekt_nodes_status_query, []).and_raise(PG::UndefinedTable)
         | 
| 101 109 |  | 
| 102 110 | 
             
                      expect(collector.run).to eq({ task_processing_query_result: zoekt_tasks_processing_query_results })
         | 
| 103 111 | 
             
                    end
         |