CGI-FR / CGI-FR/SIGO

[FEAT][API] Create Privacy Metrics Multi Table Job

Open
#73 0 comments 0 reactions 0 assignees View on GitHub
api octopize
Dominant language
Go
Stars
6
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Description
Create a privacy metrics job for multi-table.

## Request

### Method
POST

### URL
```
/jobs/metrics/privacy_multi_table
```

### Request Parameters
None

### Request Body
```json
{
"kind": "privacy_metrics_multi_table",
"parameters": {
"privacy_metric_queries": [
{
"table_reference": {
"project_id": "my-project",
"dataset_id": "my-dataset",
"table_id": "my-table"
},
"privacy_metrics": [
{
"type": "INFO_TYPE_COUNT",
"config": {
"info_types": [
{
"name": "PERSON_NAME"
},
{
"name": "EMAIL_ADDRESS"
}
]
}
}
]
}
],
"privacy_budget": 0.5,
"job_config": {}
}
}
```

## Result

### Result parameters
None

### Result Body
```json
{
"id": "job-id",
"kind": "privacy_metrics_multi_table",
"created_at": "2023-03-08T18:30:00Z",
"status": "PENDING",
"parameters": {
"privacy_metric_queries": [
{
"table_reference": {
"project_id": "my-project",
"dataset_id": "my-dataset",
"table_id": "my-table"
},
"privacy_metrics": [
{
"type": "INFO_TYPE_COUNT",
"config": {
"info_types": [
{
"name": "PERSON_NAME"
},
{
"name": "EMAIL_ADDRESS"
}
]
}
}
]
}
],
"privacy_budget": 0.5,
"job_config": {}
}
}
```

## Example Curl Request

### Request
```
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"kind": "privacy_metrics_multi_table",
"parameters": {
"privacy_metric_queries": [
{
"table_reference": {
"project_id": "my-project",
"dataset_id": "my-dataset",
"table_id": "my-table"
},
"privacy_metrics": [
{
"type": "INFO_TYPE_COUNT",
"config": {
"info_types": [
{
"name": "PERSON_NAME"
},
{
"name": "EMAIL_ADDRESS"
}
]
}
}
]
}
],
"privacy_budget": 0.5,
"job_config": {}
}
}' \
http://localhost:8080/jobs/metrics/privacy_multi_table
```

### Curl Response
```
{
"id": "job-id",
"kind": "privacy_metrics_multi_table",
"created_at": "2023-03-08T18:30:00Z",
"status": "PENDING",
"parameters": {
"privacy_metric_queries": [
{
"table_reference": {
"project_id": "my-project",
"dataset_id": "my-dataset",
"table_id": "my-table"
},
"privacy_metrics": [
{
"type": "INFO_TYPE_COUNT",
"config": {
"info_types": [
{
"name": "PERSON_NAME"
},
{
"name": "EMAIL_ADDRESS"
}
]
}
}
]
}
],
"privacy_budget": 0.5,
"job_config": {}
}
}
```

## Go server

### Struct
```go
// PrivacyMetricsMultiTableJob is a representation of a privacy metrics job for multi-table.
type PrivacyMetricsMultiTableJob struct {
ID string `json:"id"`
Kind string `json:"kind"`
CreatedAt *time.Time `json:"created_at"`
Status string `json:"status"`
ErrorMessage *string `json:"error_message"`
TraceBack *string `json:"traceback"`
Result *MetaPrivacyMetrics `json:"result"`
Parameters *PrivacyMetricsMultiTableParams `json:"parameters"`
CurrentProgress *JobProgress `json:"current_progress"`
CreationInProgress bool `json:"-"`
LastUpdated time.Time `json:"-"`
Done bool `json:"-"`
Err error `json:"-"`
}
```

### Handler
```go
// CreatePrivacyMetricsMultiTableJob creates a privacy metrics job for multi-table.
func (s *Server) CreatePrivacyMetricsMultiTableJob(ctx context.Context, w http.ResponseWriter, r *http.Request) {
var req PrivacyMetricsMultiTableJobCreate

if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "Bad Request", http.StatusBadRequest)
return
}

if req.Kind != JobKindPrivacyMetricsMultiTable {
http.Error(w, "Bad Request", http.StatusBadRequest)
return
}

job, err := s.jobService.CreatePrivacyMetricsMultiTableJob(ctx, req.Parameters)
if err != nil {
s.logger.Errorf("Failed to create PrivacyMetricsMultiTableJob: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(job)
}
```
## Links

- [Jobs.create_privacy_metrics_multi_table_job](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L685)
- [PrivacyMetricsMultiTableJobCreate](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L685)
- [PrivacyMetricsMultiTableJob](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L685)

## Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project [avatar-python](https://github.com/octopize/avatar-python/) to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.

Best regards,
The SIGO Team

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing Go job handlers and service methods alongside the linked avatar-python API definitions. Trace how job kinds, parameters, responses, and asynchronous status are represented, then add the multi-table privacy metrics endpoint and its service integration. Done means the documented POST request returns a pending job with the shown structure and existing job behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.