Giter Site home page Giter Site logo

experiment-go-server's Introduction

experiment-go-server

Amplitude Experiment SDK for Go.

Documentation

Visit our developer docs site for the full SDK documentation.

Command-line Interface (xpmt)

The xpmt command-line interface tool allows you to make Experiment SDK calls from the command line. This tool is meant to be used for debugging and testing, not for use in production environments.

Build

Makefile currently only builds for macos (amd64 & x64), add a line to the Makefile to support your OS and Architecture.

make xpmt

Run

!!!warning Setting the deployment key All examples below assume the EXPERIMENT_KEY environment variable has been set. Alternatively, use the -k flag to set the key in the command.

Subcommands

  • fetch: fetch variants for a user from the server
  • rules: fetch flag configs (rules) from experiment
  • evaluate: fetch flag configs from experiment and evaluate the user locally

Fetch

Fetch variants via remote evaluation for the given input user.

Usage of fetch:
  -d string
        Device id to fetch variants for.
  -debug
        Log additional debug output to std out.
  -i string
        User id to fetch variants for.
  -k string
        Api key for authorization, or use EXPERIMENT_KEY env var.
  -staging
        Use skylab staging environment.
  -u string
        The full user object to fetch variants for.
  -url string
        The server url to use to fetch variants from.

Examples

Fetch variants for a user given the user ID

./xpmt fetch -i [email protected]

Fetch variants for a user given the device ID

./xpmt fetch -d Xg0nG1v3iToYA

Fetch variants for a user given an experiment user JSON object

./xpmt fetch -u '{"user_id":"[email protected]","user_properties":{"premium":true}}'

Note: must use single quotes around JSON object string

Evaluate

Fetch flag configurations and locally evaluate the user.

Usage of evaluate:
  -d string
        Device id to fetch variants for.
  -debug
        Log additional debug output to std out.
  -i string
        User id to fetch variants for.
  -k string
        Server api key for authorization, or use EXPERIMENT_KEY env var.
  -staging
        Use skylab staging environment.
  -u string
        The full user object to fetch variants for.
  -url string
        The server url to use poll for flag configs from.

Examples

Fetch variants for a user given the user ID

./xpmt evaluate -i [email protected]

Fetch variants for a user given the device ID

./xpmt evaluate -d Xg0nG1v3iToYA

Fetch variants for a user given an experiment user JSON object

./xpmt evaluate -u '{"user_id":"[email protected]","user_properties":{"premium":true}}'

Note: must use single quotes around JSON object string

experiment-go-server's People

Contributors

amplitude-sdk-bot avatar bgiori avatar qingzhuozhen avatar tyiuhc avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

experiment-go-server's Issues

CloudQuery source plugin?

Hi Team, hopefully this is right place to ask, if not, would appreciate if you can direct me.

I'm the founder of cloudquery.io, a high performance open source ELT framework.

Our users are interested in an Amplitude plugin, but as we cannot maintain all the plugins ourselves, I was curious if this would be an interesting collaboration, where we would help implement an initial source plugin, and you will help maintain it.

This will give your users the ability to sync Amplitude data to any of their datalakes/data-warehouses/databases easily using any of the growing list of CQ destination plugins.

Best,
Yevgeny

Error nil on retryFetch Function

Hi,

Context

I use this library in my golang server to fetch data from Amplitude. While testing retry, I realized enabling FetchRetries will always give error output of client.Fetch function as nil, even though there is an error.

I simulate error by setting FetchTimeout: 1 nanosecond
Below is the log for testing without using retry by setting FetchRetries: 0

func testFunc() {
	...
	client := remote.Initialize(_APIKEY_, &remote.Config{
		Debug:        true,
		FetchTimeout: 1 * time.Nanosecond,
		RetryBackoff: &remote.RetryBackoff{
			FetchRetries:            0,
			FetchRetryBackoffMin:    100 * time.Millisecond,
			FetchRetryBackoffMax:    1 * time.Second,
			FetchRetryBackoffScalar: 2,
		},
	})
	variants, err := client.Fetch(__user__)
	if err != nil {
		fmt.Println("Error fetch: ", err)

		if err, ok := (err).(net.Error); ok && err.Timeout() {
			fmt.Println("Error timeout: ", err)
		}
		return
	}
	payload = variants[__key__].Payload
	if payload == nil {
		fmt.Println("empty payload")
	}
	...
}

Screen Shot 2022-06-20 at 20 36 12

From the result, we can see that the timeout error was returned by Fetch function.

Current Behavior

On the other hand, when I set FetchRetries: 5, the timeout error does not returned by Fetch function, instead, it returned nil error with empty result. We can see that on the log below.

Screen Shot 2022-06-20 at 20 49 09

See the red boxes. Every retries gave timeout error, but the conclusion have the error as <nil> that returned as Fetch results. This issue make it hard to handle error separately and track the error code for alert or debugging.

Expected Behavior

Even in retryFetch, the Fetch function should return the error, at least error from the last retry.

Possible Solution

Deep-dive further to the code, in the client.go file. I think the issue happen because of the code in yellow block. Instead of set the value of err variable that created in line 97, the code in line 104 create new local variable (scoped inside for block). Hence, the error that printed and returned in lines 115-116 is always be nil.

Screen Shot 2022-06-20 at 21 07 38

I think the issue can be solved by declaring the variables variants and err before the for loop, then just use assignment without initialization when call doFetch function.
Screen Shot 2022-06-20 at 21 18 31

Question

Is this an expected behavior for retryFetch function?

Other

Go version: 1.17

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.