+
Skip to content

will-rowe/hn

Repository files navigation

HN - Reporting Service

CI

A service to allow licensees to report individual pieces of data (text, image, audio, video, animation) that may be in violation of laws or regulations (e.g. contains PII). The service accepts structured violation reports and returns a report ID for tracking and audit purposes.

Assumptions

  • The service runs as a single instance (no load balancing or distributed coordination needed).
  • No persistence is required — reports are processed and acknowledged, but not stored.
  • The backend is implemented in Go, using gRPC and gRPC-Gateway to expose both REST and gRPC interfaces.
  • A valid Bearer token is required to access the endpoint (currently a static token for development/testing).
  • Protobuf definitions are managed via Buf and used to generate server and client code.
  • Mock interfaces are generated using Mockery.

Installing

We use mise to manage the dependencies and tasks for running this project.

  1. Install mise
curl https://mise.run | sh
  1. Clone this repo, trust the mise config and install the dependencies
git clone https://github.com/will-rowe/hn && cd hn
mise trust .
mise install
  1. Generate the required files
mise tasks run generate
  1. Run the linting and tests:
mise tasks run test
  1. Start the server with Docker Compose (with an initial run of the e2e):
mise tasks run start
  1. Run the full end-to-end test (starts the server, runs the e2e test, then exits):
mise tasks run e2e

API

The API exposes a single endpoint:

POST /v1/reports
Authorization: Bearer <token>
Content-Type: application/json

Request

{
  "dataset_id": "abc123",
  "data_id": "def456",
  "media_type": "MEDIA_TYPE_TEXT",
  "violation_type": "VIOLATION_TYPE_PII",
  "description": "This contains personally identifiable information."
}

Response

{
  "report_id": "report-uuid",
  "status": "RECEIVED"
}

The API is defined via Protobuf (report.proto) and includes both REST and gRPC bindings.

Testing and performance

Unit tests

  • All handler and service logic is unit tested using testify.
  • The ReportServiceInterface is mocked using Mockery.
  • Tests cover validation, correct response behavior, and error cases.
  • Run with:
mise tasks run test

Latency Benchmarks

Use Go’s built-in benchmarking tools to measure performance of critical functions like ProcessReport():

func BenchmarkProcessReport(b *testing.B) {
    svc := NewReportService()
    req := &report.ReportRequest{
        DatasetId: "ds1", DataId: "data1", Description: "Contains PII",
        MediaType: report.MediaType_TEXT, ViolationType: report.ViolationType_PII,
    }

    for i := 0; i < b.N; i++ {
        _, _ = svc.ProcessReport(context.Background(), req)
    }
}

Run benchmarks with:

go test -bench=. ./backend/reporting

You can use pprof for deeper CPU and memory profiling.

End to end

You can run the server locally and send a report using curl:

go run main.go

Then, in another terminal:

curl -X POST http://localhost:8080/v1/reports \
  -H "Authorization: Bearer testtoken" \
  -H "Content-Type: application/json" \
  -d '{
        "dataset_id": "abc123",
        "data_id": "def456",
        "media_type": "MEDIA_TYPE_TEXT",
        "violation_type": "VIOLATION_TYPE_PII",
        "description": "Contains a full name and email address"
      }'

A valid JSON response with report_id and status should be returned.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载