Skip to content

MaxMind GeoIP - #6

Merged
Ret2Hell merged 9 commits into
mainfrom
dev
Mar 30, 2026
Merged

Ret2Hell merged 9 commits into
mainfrom
dev

Conversation

@Ret2Hell

@Ret2Hell Ret2Hell commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • IP addresses are now resolved to country and region during processing; anonymization can optionally include geo-derived fields.
  • Chores

    • Added configurable GeoIP database path via environment.
    • Container image now includes the GeoIP database artifact.
    • Updated ignore rules and dependencies to support local GeoIP data.
  • Tests

    • Added GeoIP resolver tests and CI step to obtain the GeoIP database.

@coderabbitai

coderabbitai Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds GeoIP support: new GeoIPResolver using a GeoLite2 DB; config adds GEOIP_DB_PATH; Anonymizer accepts an optional resolver and performs geo resolution; main wires resolver lifecycle; Docker/CI include the DB artifact; tests updated accordingly.

Changes

Cohort / File(s) Summary
Env & Config
.env.example, internal/config/config.go
Added GEOIP_DB_PATH to .env.example; ProcessorConfig and LoadProcessorConfig() now include GeoIPDBPath sourced from GEOIP_DB_PATH.
GeoIP Implementation & Tests
internal/processors/geoip.go, internal/processors/geoip_test.go
New GeoIPResolver type with NewGeoIPResolver(dbPath), Resolve(ip) (country,region), and Close(); tests added validating public, private, and invalid IP behaviors using data/GeoLite2-City.mmdb.
Anonymizer & Tests
internal/processors/anonymizer.go, internal/processors/anonymizer_test.go
NewAnonymizer signature now accepts (*GeoIPResolver); Anonymize attempts geo resolution when resolver present; tests updated to pass nil in call sites.
Main wiring
cmd/processor/main.go
Main initializes GeoIPResolver from config, aborts on init error, defers Close(), and injects resolver into Anonymizer.
Module deps
go.mod
Added direct dependency on github.com/oschwald/geoip2-golang/v2 and adjusted redismock entry.
Build, CI & Ignore
Dockerfile, .gitignore, .github/workflows/ci.yml
Dockerfile copies data/GeoLite2-City.mmdb into image; data/ added to .gitignore; CI step added to download/extract GeoLite2 City DB using MAXMIND_LICENSE_KEY.
Test Call Sites
internal/consumer/consumer_test.go, internal/pipeline/pipeline_test.go
Updated tests to construct anonymizer with NewAnonymizer(..., nil) to match new signature.

Sequence Diagram

sequenceDiagram
    participant Main as Processor Main
    participant Config as Config Loader
    participant GeoIP as GeoIPResolver
    participant Anonymizer as Anonymizer
    participant DB as GeoIP2 Database

    Main->>Config: LoadProcessorConfig()
    Config-->>Main: ProcessorConfig{GeoIPDBPath}

    Main->>GeoIP: NewGeoIPResolver(dbPath)
    GeoIP->>DB: Open GeoIP2 DB
    DB-->>GeoIP: Reader ready
    GeoIP-->>Main: GeoIPResolver created

    Main->>Anonymizer: NewAnonymizer(salt, geoIP)
    Anonymizer-->>Main: Anonymizer ready

    Main->>Anonymizer: Anonymize(event with IP)
    Anonymizer->>GeoIP: Resolve(ip) (if geoIP != nil)
    GeoIP->>DB: Query City record
    DB-->>GeoIP: Country, Region
    GeoIP-->>Anonymizer: country, region
    Anonymizer-->>Main: Anonymized event

    Main->>GeoIP: Close()
    GeoIP->>DB: Close reader
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hop through bytes and city maps tonight,
I sniff an IP, then tuck its trace from sight.
I fetch a country, whisper region low,
I hash the rest where only carrots know.
🌿📡


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@Ret2Hell
Ret2Hell merged commit 93e30e7 into main Mar 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant