Commit 4d6efea5 authored by Terri Chu's avatar Terri Chu Committed by Nick Thomas

Log when missing project_feature during project index

Add logging to help identify why projects are missing
project_feature attributes when a validation rule
exists. This data generates errors during indexing.
parent ea698973
---
title: Add logging when indexing projects are missing project_feature attribute
merge_request: 39255
author:
type: fixed
...@@ -39,8 +39,14 @@ module Elastic ...@@ -39,8 +39,14 @@ module Elastic
# ES6 is now single-type per index, so we implement our own typing # ES6 is now single-type per index, so we implement our own typing
data['type'] = 'project' data['type'] = 'project'
# Somehow projects are being created and sent for indexing without an associated project_feature
# https://gitlab.com/gitlab-org/gitlab/-/issues/232654
# When this happens, log the errors to help with debugging, and raise the error to prevent indexing bad data
TRACKED_FEATURE_SETTINGS.each do |feature| TRACKED_FEATURE_SETTINGS.each do |feature|
data[feature] = target.project_feature.public_send(feature) # rubocop:disable GitlabSecurity/PublicSend data[feature] = target.project_feature.public_send(feature) # rubocop:disable GitlabSecurity/PublicSend
rescue NoMethodError => err
target.logger.error("Elasticsearch failed to read feature #{feature} for #{target.class} #{target.id}: #{err}")
raise
end end
data data
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Elastic::Latest::ProjectInstanceProxy do
let(:project) { create(:project) }
subject { described_class.new(project) }
describe '#as_indexed_json' do
it 'serializes project as hash' do
result = subject.as_indexed_json.with_indifferent_access
expect(result).to include(
id: project.id,
name: project.name,
path: project.path,
description: project.description,
namespace_id: project.namespace_id,
created_at: project.created_at,
updated_at: project.updated_at,
archived: project.archived,
visibility_level: project.visibility_level,
last_activity_at: project.last_activity_at,
name_with_namespace: project.name_with_namespace,
path_with_namespace: project.path_with_namespace)
Elastic::Latest::ProjectInstanceProxy::TRACKED_FEATURE_SETTINGS.each do |feature|
expect(result).to include(feature => project.project_feature.public_send(feature)) # rubocop:disable GitlabSecurity/PublicSend
end
end
it 'raises an error for a project with an empty project_feature' do
allow(project).to receive(:project_feature).and_return(nil)
expect(project.logger).to receive(:error)
expect { subject.as_indexed_json }.to raise_error NoMethodError
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment