Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
youen opened this issue Mar 31, 2024 · 0 comments
Open

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

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

Description

Create a privacy metrics job for multi-table.

Request

Method

POST

URL

/jobs/metrics/privacy_multi_table

Request Parameters

None

Request Body

{
  "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

{
  "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

// 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

// 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

Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant