-
Notifications
You must be signed in to change notification settings - Fork 7
/
provider.go
87 lines (73 loc) · 2.06 KB
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package provider
import (
"fmt"
"github.com/nuweba/faasbenchmark/provider/aws"
"github.com/nuweba/faasbenchmark/provider/azure"
"github.com/nuweba/faasbenchmark/provider/google"
"github.com/nuweba/faasbenchmark/report"
"github.com/nuweba/faasbenchmark/stack"
"github.com/nuweba/httpbench/engine"
"github.com/nuweba/httpbench/syncedtrace"
"github.com/pkg/errors"
"net/http"
"net/url"
"strings"
"time"
)
type RequestFilter = func(sleepTime time.Duration, tr *engine.TraceResult, funcDuration time.Duration, reused bool) (report.Result, error)
type Filter interface {
HttpResult(sleepTime time.Duration, tr *engine.TraceResult, funcDuration time.Duration, reused bool) (report.Result, error)
}
type FaasProvider interface {
Filter
Name() string
HttpInvocationTriggerStage() syncedtrace.TraceHookType
NewStack(stackPath string) (stack.Stack, error)
NewFunctionRequest(stack stack.Stack, function stack.Function, qParams *url.Values, headers *http.Header, body *[]byte) func(uniqueId string) (*http.Request, error)
}
type Providers int
const (
AWS Providers = iota
Google
Azure
ProvidersCount
)
func (p Providers) String() string {
return [...]string{
"aws",
"google",
"azure",
}[p]
}
func (p Providers) Description() string {
return [...]string{
"aws lambda functions",
"google cloud functions",
"azure functions",
}[p]
}
func NewProvider(providerName string) (FaasProvider, error) {
var faasProvider FaasProvider
var err error
switch strings.ToLower(providerName) {
case strings.ToLower(AWS.String()):
faasProvider, err = aws.New()
case strings.ToLower(Google.String()):
faasProvider, err = google.New()
case strings.ToLower(Azure.String()):
faasProvider, err = azure.New()
default:
faasProvider, err = nil, errors.New(fmt.Sprintf("provider not supported: %s", providerName))
}
if err != nil {
return nil, err
}
return faasProvider, nil
}
func List() []string {
var providers []string
for providerId := Providers(0); providerId < ProvidersCount; providerId++ {
providers = append(providers, providerId.String())
}
return providers
}