mirror of
https://github.com/hanzo-go/sdk.git
synced 2026-11-20 20:13:42 +00:00
959 lines
35 KiB
Go
959 lines
35 KiB
Go
/*
|
|
Hanzo Cloud API
|
|
|
|
The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
|
|
|
|
API version: v1
|
|
*/
|
|
|
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
|
|
|
package hanzoai
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// ExperimentAPIService ExperimentAPI service
|
|
type ExperimentAPIService service
|
|
|
|
type ExperimentAPIGetExperimentRequest struct {
|
|
ctx context.Context
|
|
ApiService *ExperimentAPIService
|
|
}
|
|
|
|
func (r ExperimentAPIGetExperimentRequest) Execute() (*ExperimentExperimentList, *http.Response, error) {
|
|
return r.ApiService.GetExperimentExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetExperiment Is every experiment in the caller's org, with its variants, status and decision, ordered by project then id.
|
|
|
|
Is every experiment in the caller's org, with its variants, status and
|
|
decision, ordered by project then id.
|
|
|
|
Scoped to the org resolved from the validated principal — a distinct org is a
|
|
distinct physical store, so no query here can reach another tenant's rows — and
|
|
further narrowed to the caller's project scope when the credential carries one.
|
|
A principal with NO project scope sees the org's experiments across all of its
|
|
projects, which is the answer a reader most often expects to be filtered and is
|
|
not.
|
|
|
|
Requires a validated principal; refuses without one rather than answering an
|
|
empty list.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return ExperimentAPIGetExperimentRequest
|
|
*/
|
|
func (a *ExperimentAPIService) GetExperiment(ctx context.Context) ExperimentAPIGetExperimentRequest {
|
|
return ExperimentAPIGetExperimentRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return ExperimentExperimentList
|
|
func (a *ExperimentAPIService) GetExperimentExecute(r ExperimentAPIGetExperimentRequest) (*ExperimentExperimentList, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *ExperimentExperimentList
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExperimentAPIService.GetExperiment")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/experiment"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ExperimentAPIGetExperimentByIdRequest struct {
|
|
ctx context.Context
|
|
ApiService *ExperimentAPIService
|
|
id string
|
|
}
|
|
|
|
func (r ExperimentAPIGetExperimentByIdRequest) Execute() (*ExperimentTrial, *http.Response, error) {
|
|
return r.ApiService.GetExperimentByIdExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetExperimentById Is one experiment's definition and lifecycle: variants, weights, control arm, status and winner.
|
|
|
|
Is one experiment's definition and lifecycle: variants, weights, control
|
|
arm, status and winner.
|
|
|
|
It reads the registry row only — the definition and the decision, never live
|
|
measurements. Assignment lives in the flags plane and outcomes in analytics;
|
|
this is the value that names both.
|
|
|
|
Scoped to the caller's org and project from the validated principal, so another
|
|
tenant's experiment of the same id is simply not found. An id that is not a
|
|
legal slug is answered the same way, without a store read — the shape check and
|
|
the existence check are one answer, so neither leaks the other.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@param id ID is the experiment the URL names.
|
|
@return ExperimentAPIGetExperimentByIdRequest
|
|
*/
|
|
func (a *ExperimentAPIService) GetExperimentById(ctx context.Context, id string) ExperimentAPIGetExperimentByIdRequest {
|
|
return ExperimentAPIGetExperimentByIdRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
id: id,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return ExperimentTrial
|
|
func (a *ExperimentAPIService) GetExperimentByIdExecute(r ExperimentAPIGetExperimentByIdRequest) (*ExperimentTrial, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *ExperimentTrial
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExperimentAPIService.GetExperimentById")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/experiment/{id}"
|
|
localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1)
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ExperimentAPIGetExperimentByIdAssignRequest struct {
|
|
ctx context.Context
|
|
ApiService *ExperimentAPIService
|
|
id string
|
|
subject *string
|
|
props *string
|
|
}
|
|
|
|
// Subject is the unit to bucket — a user, org, session or audience key, matching the experiment's subjectKind.
|
|
func (r ExperimentAPIGetExperimentByIdAssignRequest) Subject(subject string) ExperimentAPIGetExperimentByIdAssignRequest {
|
|
r.subject = &subject
|
|
return r
|
|
}
|
|
|
|
// Props is a JSON object of person properties for targeting. A value that is not valid JSON is dropped rather than refused, so a malformed one changes the bucketing without saying so.
|
|
func (r ExperimentAPIGetExperimentByIdAssignRequest) Props(props string) ExperimentAPIGetExperimentByIdAssignRequest {
|
|
r.props = &props
|
|
return r
|
|
}
|
|
|
|
func (r ExperimentAPIGetExperimentByIdAssignRequest) Execute() (*ExperimentAssignment, *http.Response, error) {
|
|
return r.ApiService.GetExperimentByIdAssignExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetExperimentByIdAssign Is the variant one subject is bucketed into, and the payload that variant carries.
|
|
|
|
Is the variant one subject is bucketed into, and the payload that
|
|
variant carries.
|
|
|
|
The bucketing is a deterministic hash of the subject, so the same subject gets
|
|
the same arm on every call for as long as the flag definition is unchanged —
|
|
and this is a pure READ: it records nothing. In particular it does NOT record an
|
|
exposure. The caller's SDK must emit the experiment's exposure event itself, or
|
|
the analysis has an empty denominator and every arm measures zero.
|
|
|
|
An empty variant with on false is not an error — it means the flag returned
|
|
nothing for this subject, so the subject is not enrolled. A flags engine that is
|
|
unavailable refuses rather than defaulting to an arm. Requires a validated
|
|
principal, and the experiment must exist in the caller's org and project.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@param id ID is the experiment the URL names.
|
|
@return ExperimentAPIGetExperimentByIdAssignRequest
|
|
*/
|
|
func (a *ExperimentAPIService) GetExperimentByIdAssign(ctx context.Context, id string) ExperimentAPIGetExperimentByIdAssignRequest {
|
|
return ExperimentAPIGetExperimentByIdAssignRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
id: id,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return ExperimentAssignment
|
|
func (a *ExperimentAPIService) GetExperimentByIdAssignExecute(r ExperimentAPIGetExperimentByIdAssignRequest) (*ExperimentAssignment, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *ExperimentAssignment
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExperimentAPIService.GetExperimentByIdAssign")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/experiment/{id}/assign"
|
|
localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1)
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.subject == nil {
|
|
return localVarReturnValue, nil, reportError("subject is required and must be specified")
|
|
}
|
|
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "subject", r.subject, "form", "")
|
|
if r.props != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "props", r.props, "form", "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ExperimentAPIGetExperimentHealthRequest struct {
|
|
ctx context.Context
|
|
ApiService *ExperimentAPIService
|
|
}
|
|
|
|
func (r ExperimentAPIGetExperimentHealthRequest) Execute() (*ExperimentHealth, *http.Response, error) {
|
|
return r.ApiService.GetExperimentHealthExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetExperimentHealth Is whether the experiments subsystem is mounted and serving in this process.
|
|
|
|
Is whether the experiments subsystem is mounted and serving in this
|
|
process.
|
|
|
|
It answers unconditionally. It proves exactly one thing — that this binary
|
|
registered the experiments routes and is dispatching them — and deliberately no
|
|
more: it reads no principal, opens no per-org registry, and touches neither the
|
|
flags engine nor the analytics plane, so a 200 here says nothing about whether a
|
|
given tenant's store will open or whether an analysis can run. It is the only
|
|
route on this surface that needs no org.
|
|
|
|
The static path is registered ahead of the /:id read, so it always wins the
|
|
first-match scan. "health" is a legal experiment id, which means an experiment
|
|
created under that id can never be fetched by id — pick another.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return ExperimentAPIGetExperimentHealthRequest
|
|
*/
|
|
func (a *ExperimentAPIService) GetExperimentHealth(ctx context.Context) ExperimentAPIGetExperimentHealthRequest {
|
|
return ExperimentAPIGetExperimentHealthRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return ExperimentHealth
|
|
func (a *ExperimentAPIService) GetExperimentHealthExecute(r ExperimentAPIGetExperimentHealthRequest) (*ExperimentHealth, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *ExperimentHealth
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExperimentAPIService.GetExperimentHealth")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/experiment/health"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ExperimentAPIPostExperimentRequest struct {
|
|
ctx context.Context
|
|
ApiService *ExperimentAPIService
|
|
experimentCreateBody *ExperimentCreateBody
|
|
}
|
|
|
|
func (r ExperimentAPIPostExperimentRequest) ExperimentCreateBody(experimentCreateBody ExperimentCreateBody) ExperimentAPIPostExperimentRequest {
|
|
r.experimentCreateBody = &experimentCreateBody
|
|
return r
|
|
}
|
|
|
|
func (r ExperimentAPIPostExperimentRequest) Execute() (*ExperimentTrial, *http.Response, error) {
|
|
return r.ApiService.PostExperimentExecute(r)
|
|
}
|
|
|
|
/*
|
|
PostExperiment Registers a controlled experiment AND puts its assignment flag live, in that order, so the arms start bucketing subjects the moment this returns 201 — the flag is created active at 100% rollout, with each variant weighted as declared.
|
|
|
|
Registers a controlled experiment AND puts its assignment flag live, in
|
|
that order, so the arms start bucketing subjects the moment this returns 201 —
|
|
the flag is created active at 100% rollout, with each variant weighted as
|
|
declared. There is no separate start call; creating IS starting.
|
|
|
|
A variant carries an opaque payload this primitive never interprets: a feature
|
|
config, an ad-creative id, a subject line, a model id.
|
|
|
|
Requires a validated principal, and refuses without one. The org and project are
|
|
taken from that principal and the creator is stamped from the credential — none
|
|
of the three is a body field, so an experiment cannot be filed against another
|
|
tenant. An id already used in this project is a conflict, never a silent
|
|
overwrite: re-creating would stomp the assignment flag of a run in progress.
|
|
|
|
It fails closed on the flag write. An experiment whose assignment flag does not
|
|
exist would assign nobody, so if that write fails nothing is registered.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return ExperimentAPIPostExperimentRequest
|
|
*/
|
|
func (a *ExperimentAPIService) PostExperiment(ctx context.Context) ExperimentAPIPostExperimentRequest {
|
|
return ExperimentAPIPostExperimentRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return ExperimentTrial
|
|
func (a *ExperimentAPIService) PostExperimentExecute(r ExperimentAPIPostExperimentRequest) (*ExperimentTrial, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodPost
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *ExperimentTrial
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExperimentAPIService.PostExperiment")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/experiment"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.experimentCreateBody == nil {
|
|
return localVarReturnValue, nil, reportError("experimentCreateBody is required and must be specified")
|
|
}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{"application/json"}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
// body params
|
|
localVarPostBody = r.experimentCreateBody
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ExperimentAPIPostExperimentByIdAnalyzeRequest struct {
|
|
ctx context.Context
|
|
ApiService *ExperimentAPIService
|
|
id string
|
|
experimentAnalyzeQuery *ExperimentAnalyzeQuery
|
|
}
|
|
|
|
func (r ExperimentAPIPostExperimentByIdAnalyzeRequest) ExperimentAnalyzeQuery(experimentAnalyzeQuery ExperimentAnalyzeQuery) ExperimentAPIPostExperimentByIdAnalyzeRequest {
|
|
r.experimentAnalyzeQuery = &experimentAnalyzeQuery
|
|
return r
|
|
}
|
|
|
|
func (r ExperimentAPIPostExperimentByIdAnalyzeRequest) Execute() (*ExperimentAnalysis, *http.Response, error) {
|
|
return r.ApiService.PostExperimentByIdAnalyzeExecute(r)
|
|
}
|
|
|
|
/*
|
|
PostExperimentByIdAnalyze Is per-variant conversion, lift and statistical significance against the control arm.
|
|
|
|
Is per-variant conversion, lift and statistical significance against
|
|
the control arm.
|
|
|
|
It reads per-subject outcomes from the analytics plane over a window, folds them
|
|
into per-variant samples, and returns each arm's exposed count, conversions,
|
|
rate, lift versus control, two-proportion z, two-tailed p-value and whether it
|
|
clears alpha. Arms with no data still appear with zero exposed, so the read is
|
|
complete over the experiment's declared arms; the control arm sorts first. The
|
|
pooled-variance estimator is used and the p-value is exact; a degenerate
|
|
comparison (an empty arm, no variance) answers z 0 and p 1 — not significant,
|
|
never an error.
|
|
|
|
Only EXPOSED subjects are counted, and each is joined to its arm by re-evaluating
|
|
the assignment flag AT ANALYSIS TIME — not from what was in force during the
|
|
window. That is the one rule to get right: analyzing an experiment after its
|
|
winner has been promoted re-buckets every subject into the promoted arm,
|
|
collapsing the control to zero exposed and making the result meaningless. Read
|
|
the analysis before deciding. A subject the flag cannot place is dropped rather
|
|
than allowed to poison the fold.
|
|
|
|
The winner in the response is ADVISORY — the significant, control-beating arm
|
|
with the highest rate, or empty when inconclusive. It promotes nothing; the
|
|
decision is a separate, explicit act.
|
|
|
|
Every plane read is scoped to the caller's org. Per-variant samples are also
|
|
written to the research evidence plane as immutable ab rows, best-effort: the
|
|
analysis is still returned if that write fails, because the samples are
|
|
recomputable, and the failure is logged rather than swallowed.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@param id ID is the experiment the URL names.
|
|
@return ExperimentAPIPostExperimentByIdAnalyzeRequest
|
|
*/
|
|
func (a *ExperimentAPIService) PostExperimentByIdAnalyze(ctx context.Context, id string) ExperimentAPIPostExperimentByIdAnalyzeRequest {
|
|
return ExperimentAPIPostExperimentByIdAnalyzeRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
id: id,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return ExperimentAnalysis
|
|
func (a *ExperimentAPIService) PostExperimentByIdAnalyzeExecute(r ExperimentAPIPostExperimentByIdAnalyzeRequest) (*ExperimentAnalysis, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodPost
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *ExperimentAnalysis
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExperimentAPIService.PostExperimentByIdAnalyze")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/experiment/{id}/analyze"
|
|
localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1)
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.experimentAnalyzeQuery == nil {
|
|
return localVarReturnValue, nil, reportError("experimentAnalyzeQuery is required and must be specified")
|
|
}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{"application/json"}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
// body params
|
|
localVarPostBody = r.experimentAnalyzeQuery
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type ExperimentAPIPostExperimentByIdDecideRequest struct {
|
|
ctx context.Context
|
|
ApiService *ExperimentAPIService
|
|
id string
|
|
experimentDecideBody *ExperimentDecideBody
|
|
}
|
|
|
|
func (r ExperimentAPIPostExperimentByIdDecideRequest) ExperimentDecideBody(experimentDecideBody ExperimentDecideBody) ExperimentAPIPostExperimentByIdDecideRequest {
|
|
r.experimentDecideBody = &experimentDecideBody
|
|
return r
|
|
}
|
|
|
|
func (r ExperimentAPIPostExperimentByIdDecideRequest) Execute() (*ExperimentTrial, *http.Response, error) {
|
|
return r.ApiService.PostExperimentByIdDecideExecute(r)
|
|
}
|
|
|
|
/*
|
|
PostExperimentByIdDecide Promotes one variant to the whole rollout and records who decided.
|
|
|
|
Promotes one variant to the whole rollout and records who decided.
|
|
|
|
It rewrites the assignment flag so the named winner serves 100% of the rollout
|
|
and every other arm 0%, preserving the flag's targeting groups and payloads,
|
|
then stamps the experiment decided with the winner, the deciding credential and
|
|
the time. This is a production behaviour change that takes effect immediately
|
|
for every subject the flag evaluates.
|
|
|
|
It requires an ORG ADMIN of the caller's own org — a stricter gate than the rest
|
|
of this surface, matching the flags write plane, because promoting is a flag
|
|
write. The admin check runs AFTER the experiment is found, so a caller from
|
|
another tenant is answered not-found rather than forbidden and learns nothing
|
|
about what exists.
|
|
|
|
An experiment whose assignment flag has gone missing is a conflict rather than a
|
|
silent no-op — there is nothing to promote.
|
|
|
|
Deciding is NOT terminal. A second call re-promotes a different variant and
|
|
re-stamps the row; the status stays decided and the previous winner is
|
|
overwritten with no record that it was ever chosen. Nothing here reverts the
|
|
flag to its original weights either, so an experiment cannot be un-decided
|
|
through this route — restoring a split means writing the flag definition back
|
|
through the flags plane.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@param id
|
|
@return ExperimentAPIPostExperimentByIdDecideRequest
|
|
*/
|
|
func (a *ExperimentAPIService) PostExperimentByIdDecide(ctx context.Context, id string) ExperimentAPIPostExperimentByIdDecideRequest {
|
|
return ExperimentAPIPostExperimentByIdDecideRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
id: id,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return ExperimentTrial
|
|
func (a *ExperimentAPIService) PostExperimentByIdDecideExecute(r ExperimentAPIPostExperimentByIdDecideRequest) (*ExperimentTrial, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodPost
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *ExperimentTrial
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExperimentAPIService.PostExperimentByIdDecide")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/experiment/{id}/decide"
|
|
localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1)
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.experimentDecideBody == nil {
|
|
return localVarReturnValue, nil, reportError("experimentDecideBody is required and must be specified")
|
|
}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{"application/json"}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
// body params
|
|
localVarPostBody = r.experimentDecideBody
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|