# Audit NG

## Overview

Audit NG is a standalone service designed to run as a sidecar container alongside TiDB instances in Kubernetes
environments. It monitors audit and slow query logs generated by TiDB, rotates them, and automatically uploads them to
various cloud storage backends (AWS S3, Google Cloud Storage, Azure Blob Storage, AliCloud OSS) while managing disk
space efficiently.

## Architecture

```
┌─────────────┐   ┌──────────────┐   ┌──────────────────┐
│    TiDB     │──▶│   Audit NG   │──▶│   Cloud Storage  │
│             │   │              │   │(S3/GCS/Azure/OSS)│
│ • Audit Log │   │ • Log Watch  │   │                  │
│ • Slow Log  │   │ • Rotation   │   │                  │
└─────────────┘   │ • Upload     │   └──────────────────┘
                  │ • Clean      │
                  └──────────────┘
```

## Project Structure

```
internal/audit-ng/
├── cmd/                    # CLI commands
│   ├── root.go            # Root command and config loading
│   └── audit_server.go    # Server command implementation
├── server/                 # Core server implementation
│   ├── server.go          # Main server logic and orchestration
│   ├── handler.go         # LogHandler interface definition
│   ├── s3_handler.go      # AWS S3 storage implementation
│   ├── gcs_handler.go     # Google Cloud Storage implementation
│   ├── azblob_handler.go  # Azure Blob Storage implementation
│   ├── metrics.go         # Prometheus metrics definitions
│   └── *_test.go          # Unit tests
├── main.go                # Application entry point
├── go.mod                 # Go module definition
├── Makefile              # Build and development commands
└── Dockerfile            # Container image definition
```
