Commit 5ea5e9fd authored by Nick Thomas's avatar Nick Thomas Committed by Mayra Cabrera
Browse files

Merge branch 'tc-geo-primary-prometheus' into 'master'

Also log Prometheus metrics from the primary

Closes #5373

See merge request gitlab-org/gitlab-ee!5058
parent 58d26fa4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -7,9 +7,9 @@ def execute

      if Gitlab::Geo.primary?
        fetch_secondary_geo_nodes_metrics
      else
        fetch_current_geo_node_metrics
      end

      fetch_current_geo_node_metrics
    end

    private
+5 −0
Original line number Diff line number Diff line
---
title: Also log Geo Prometheus metrics from primary
merge_request: 5058
author:
type: added
+23 −4
Original line number Diff line number Diff line
@@ -49,6 +49,22 @@
    }
  end

  let(:primary_data) do
    {
      success: true,
      status_message: nil,
      repositories_count: 10,
      wikis_count: 10,
      lfs_objects_count: 100,
      job_artifacts_count: 100,
      attachments_count: 30,
      last_event_id: 2,
      last_event_date: event_date,
      event_log_count: 55,
      event_log_max_id: 555
    }
  end

  before do
    allow(Gitlab::Metrics).to receive(:prometheus_metrics_enabled?).and_return(true)
  end
@@ -77,16 +93,19 @@
      end

      it 'attempts to retrieve metrics from all nodes' do
        allow(GeoNodeStatus).to receive(:current_node_status).and_return(GeoNodeStatus.from_json(primary_data.as_json))

        subject.execute

        expect(Gitlab::Metrics.registry.get(:geo_db_replication_lag_seconds).values.count).to eq(2)
        expect(Gitlab::Metrics.registry.get(:geo_repositories).values.count).to eq(2)
        expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: secondary.url })).to eq(10)
        expect(Gitlab::Metrics.registry.get(:geo_repositories).values.count).to eq(3)
        expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: secondary.url })).to eq(10)
        expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: another_secondary.url })).to eq(10)
        expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: primary.url })).to eq(10)
      end

      it 'updates the GeoNodeStatus entry' do
        expect { subject.execute }.to change { GeoNodeStatus.count }.by(2)
        expect { subject.execute }.to change { GeoNodeStatus.count }.by(3)

        status = secondary.status.load_data_from_current_node

@@ -97,7 +116,7 @@
      it 'updates only the active node' do
        secondary.update_attributes(enabled: false)

        expect { subject.execute }.to change { GeoNodeStatus.count }.by(1)
        expect { subject.execute }.to change { GeoNodeStatus.count }.by(2)

        expect(another_secondary.status).not_to be_nil
      end