InfoGrab Docs

보안 인벤토리를 위한 백그라운드 작업

요약

이 문서는 보안 인벤토리에서 장기 실행 대량 작업을 추적하는 백그라운드 작업 시스템에 대해 설명합니다. 백그라운드 작업을 통해 사용자는 여러 프로젝트에서 비동기적으로 대량 작업을 수행할 수 있습니다. security_bulk_operations_notifications 기능 플래그가 백그라운드 작업 추적을 제어합니다.

이 문서는 보안 인벤토리에서 장기 실행 대량 작업을 추적하는 백그라운드 작업 시스템에 대해 설명합니다.

목적#

백그라운드 작업을 통해 사용자는 여러 프로젝트에서 비동기적으로 대량 작업을 수행할 수 있습니다. 이 시스템은 오류 추적과 실패 시 이메일 알림을 제공합니다.

아키텍처#

흐름#

Mermaid 다이어그램 (8줄)
소스 코드 보기
flowchart LR
  A[BulkUpdateService] --> B[BulkUpdateSchedulerWorker]
  B --> C[BackgroundOperationBulkUpdateWorker]
  C --> D{Failures?}
  D -->|Yes| E[Email Notification]
  D -->|No| F[Cleanup]
  B --> G[Create Redis Operation]
  C --> H[Update Counters]
  1. 시작: 사용자가 BulkUpdateService를 통해 대량 작업 트리거
  2. 예약: BulkUpdateSchedulerWorker가 프로젝트를 수집하고 Redis 작업 생성
  3. 처리: BackgroundOperationBulkUpdateWorker가 배치로 프로젝트 처리
  4. 완료: 마지막 배치가 완료를 감지하고 실패가 발생한 경우 이메일 전송
  5. 정리: 알림 후 Redis 엔티티 삭제

구성 요소#

구성 요소 목적
Security::Attributes::BulkUpdateSchedulerWorker 배치 예약 조율, Redis 작업 생성
Security::Attributes::BackgroundOperationBulkUpdateWorker 추적과 함께 프로젝트 처리
Gitlab::BackgroundOperations::RedisStore Redis 상태 관리
Security::BackgroundOperationMailer 실패 알림 이메일

Redis 데이터 구조#

작업 엔티티#

Key: background_operation:{operation_id}
Type: Hash
Fields:
  - id: 작업 ID
  - operation_type: 작업 유형(예: 'attribute_update')
  - user_id: 시작한 사용자
  - parameters: 작업별 매개변수가 있는 JSON
  - status: 'pending' | 'running'
  - total_items: 처리할 총 프로젝트 수
  - successful_items: 성공한 프로젝트 수
  - failed_items: 실패한 프로젝트 수
  - created_at: 타임스탬프
TTL: 72시간

실패한 항목 목록#

Key: background_operation:{operation_id}:failed_items
Type: List
Items: 다음이 포함된 JSON 객체:
  - entity_id: 실패한 엔티티의 ID(프로젝트 또는 그룹)
  - entity_type: 'Project' 또는 'Group'
  - entity_name: 엔티티 이름
  - entity_full_path: 링크를 위한 전체 경로
  - error_message: 사람이 읽을 수 있는 오류
  - error_code: 기계가 읽을 수 있는 오류 코드
  - created_at: 타임스탬프
TTL: 72시간

오류 코드#

코드 의미
service_error 서비스가 오류 응답을 반환함
unexpected_error 예상치 못한 예외 발생

기능 플래그#

security_bulk_operations_notifications 기능 플래그가 백그라운드 작업 추적을 제어합니다.

  • 비활성화: 레거시 BulkUpdateWorker 사용(추적 또는 알림 없음)
  • 활성화: BackgroundOperationBulkUpdateWorker 사용(추적 및 알림 포함)

이메일 알림#

이메일은 작업 완료 후 실패가 발생한 경우에만 전송됩니다.

이메일에 포함되는 내용:

  • 요약: 총계, 성공 수, 실패 수
  • 오류 세부 정보 및 링크가 있는 실패한 항목(프로젝트 또는 그룹) 목록

사용법#

작업 생성#

operation_id = Gitlab::BackgroundOperations::RedisStore.create_operation(
  operation_type: 'attribute_update',
  user_id: user.id,
  total_items: projects_count,
  parameters: { attribute_ids: [1, 2], mode: 'ADD' }
)

성공 또는 실패 기록#

# 성공 기록
Gitlab::BackgroundOperations::RedisStore.increment_successful(operation_id)

# 프로젝트의 실패 기록
Gitlab::BackgroundOperations::RedisStore.add_failed_item(
  operation_id,
  entity_id: project.id,
  entity_type: 'Project',
  entity_name: project.name,
  entity_full_path: project.full_path,
  error_message: 'Permission denied',
  error_code: 'service_error'
)

# 그룹의 실패 기록
Gitlab::BackgroundOperations::RedisStore.add_failed_item(
  operation_id,
  entity_id: group.id,
  entity_type: 'Group',
  entity_name: group.name,
  entity_full_path: group.full_path,
  error_message: 'Permission denied',
  error_code: 'service_error'
)

작업 상태 확인#

operation = Gitlab::BackgroundOperations::RedisStore.get_operation(operation_id)
# Operation 구조체를 반환: id, operation_type, user_id, parameters,
#   total_items, successful_items, failed_items

failed_items = Gitlab::BackgroundOperations::RedisStore.get_failed_items(operation_id)
# 실패한 항목 해시의 배열 반환

정리#

Gitlab::BackgroundOperations::RedisStore.delete_operation(operation_id)
# 작업 해시와 실패한 항목 목록 모두 삭제

관련 주제#

보안 인벤토리를 위한 백그라운드 작업

원문 보기
요약

이 문서는 보안 인벤토리에서 장기 실행 대량 작업을 추적하는 백그라운드 작업 시스템에 대해 설명합니다. 백그라운드 작업을 통해 사용자는 여러 프로젝트에서 비동기적으로 대량 작업을 수행할 수 있습니다. security_bulk_operations_notifications 기능 플래그가 백그라운드 작업 추적을 제어합니다.

이 문서는 보안 인벤토리에서 장기 실행 대량 작업을 추적하는 백그라운드 작업 시스템에 대해 설명합니다.

목적#

백그라운드 작업을 통해 사용자는 여러 프로젝트에서 비동기적으로 대량 작업을 수행할 수 있습니다. 이 시스템은 오류 추적과 실패 시 이메일 알림을 제공합니다.

아키텍처#

흐름#

Mermaid 다이어그램 (8줄)
소스 코드 보기
flowchart LR
  A[BulkUpdateService] --> B[BulkUpdateSchedulerWorker]
  B --> C[BackgroundOperationBulkUpdateWorker]
  C --> D{Failures?}
  D -->|Yes| E[Email Notification]
  D -->|No| F[Cleanup]
  B --> G[Create Redis Operation]
  C --> H[Update Counters]
  1. 시작: 사용자가 BulkUpdateService를 통해 대량 작업 트리거
  2. 예약: BulkUpdateSchedulerWorker가 프로젝트를 수집하고 Redis 작업 생성
  3. 처리: BackgroundOperationBulkUpdateWorker가 배치로 프로젝트 처리
  4. 완료: 마지막 배치가 완료를 감지하고 실패가 발생한 경우 이메일 전송
  5. 정리: 알림 후 Redis 엔티티 삭제

구성 요소#

구성 요소 목적
Security::Attributes::BulkUpdateSchedulerWorker 배치 예약 조율, Redis 작업 생성
Security::Attributes::BackgroundOperationBulkUpdateWorker 추적과 함께 프로젝트 처리
Gitlab::BackgroundOperations::RedisStore Redis 상태 관리
Security::BackgroundOperationMailer 실패 알림 이메일

Redis 데이터 구조#

작업 엔티티#

Key: background_operation:{operation_id}
Type: Hash
Fields:
  - id: 작업 ID
  - operation_type: 작업 유형(예: 'attribute_update')
  - user_id: 시작한 사용자
  - parameters: 작업별 매개변수가 있는 JSON
  - status: 'pending' | 'running'
  - total_items: 처리할 총 프로젝트 수
  - successful_items: 성공한 프로젝트 수
  - failed_items: 실패한 프로젝트 수
  - created_at: 타임스탬프
TTL: 72시간

실패한 항목 목록#

Key: background_operation:{operation_id}:failed_items
Type: List
Items: 다음이 포함된 JSON 객체:
  - entity_id: 실패한 엔티티의 ID(프로젝트 또는 그룹)
  - entity_type: 'Project' 또는 'Group'
  - entity_name: 엔티티 이름
  - entity_full_path: 링크를 위한 전체 경로
  - error_message: 사람이 읽을 수 있는 오류
  - error_code: 기계가 읽을 수 있는 오류 코드
  - created_at: 타임스탬프
TTL: 72시간

오류 코드#

코드 의미
service_error 서비스가 오류 응답을 반환함
unexpected_error 예상치 못한 예외 발생

기능 플래그#

security_bulk_operations_notifications 기능 플래그가 백그라운드 작업 추적을 제어합니다.

  • 비활성화: 레거시 BulkUpdateWorker 사용(추적 또는 알림 없음)
  • 활성화: BackgroundOperationBulkUpdateWorker 사용(추적 및 알림 포함)

이메일 알림#

이메일은 작업 완료 후 실패가 발생한 경우에만 전송됩니다.

이메일에 포함되는 내용:

  • 요약: 총계, 성공 수, 실패 수
  • 오류 세부 정보 및 링크가 있는 실패한 항목(프로젝트 또는 그룹) 목록

사용법#

작업 생성#

operation_id = Gitlab::BackgroundOperations::RedisStore.create_operation(
  operation_type: 'attribute_update',
  user_id: user.id,
  total_items: projects_count,
  parameters: { attribute_ids: [1, 2], mode: 'ADD' }
)

성공 또는 실패 기록#

# 성공 기록
Gitlab::BackgroundOperations::RedisStore.increment_successful(operation_id)

# 프로젝트의 실패 기록
Gitlab::BackgroundOperations::RedisStore.add_failed_item(
  operation_id,
  entity_id: project.id,
  entity_type: 'Project',
  entity_name: project.name,
  entity_full_path: project.full_path,
  error_message: 'Permission denied',
  error_code: 'service_error'
)

# 그룹의 실패 기록
Gitlab::BackgroundOperations::RedisStore.add_failed_item(
  operation_id,
  entity_id: group.id,
  entity_type: 'Group',
  entity_name: group.name,
  entity_full_path: group.full_path,
  error_message: 'Permission denied',
  error_code: 'service_error'
)

작업 상태 확인#

operation = Gitlab::BackgroundOperations::RedisStore.get_operation(operation_id)
# Operation 구조체를 반환: id, operation_type, user_id, parameters,
#   total_items, successful_items, failed_items

failed_items = Gitlab::BackgroundOperations::RedisStore.get_failed_items(operation_id)
# 실패한 항목 해시의 배열 반환

정리#

Gitlab::BackgroundOperations::RedisStore.delete_operation(operation_id)
# 작업 해시와 실패한 항목 목록 모두 삭제

관련 주제#