Skip to content

Commit fa6c8db

Browse files
authored
Revert "Add traffic splitter API kind (#1213)"
This reverts commit 41e2905.
1 parent 41e2905 commit fa6c8db

File tree

16 files changed

+169
-912
lines changed

16 files changed

+169
-912
lines changed

cli/cmd/get.go

Lines changed: 39 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/cortexlabs/cortex/pkg/lib/errors"
3535
"github.com/cortexlabs/cortex/pkg/lib/exit"
3636
"github.com/cortexlabs/cortex/pkg/lib/json"
37+
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
3738
s "github.com/cortexlabs/cortex/pkg/lib/strings"
3839
"github.com/cortexlabs/cortex/pkg/lib/table"
3940
"github.com/cortexlabs/cortex/pkg/lib/telemetry"
@@ -48,21 +49,18 @@ import (
4849
)
4950

5051
const (
51-
_titleEnvironment = "env"
52-
_titleAPI = "api"
53-
_titleAPISplitter = "api splitter"
54-
_titleAPIs = "apis"
55-
_apiSplitterWeights = "weights"
56-
_titleStatus = "status"
57-
_titleUpToDate = "up-to-date"
58-
_titleStale = "stale"
59-
_titleRequested = "requested"
60-
_titleFailed = "failed"
61-
_titleLastupdated = "last update"
62-
_titleAvgRequest = "avg request"
63-
_title2XX = "2XX"
64-
_title4XX = "4XX"
65-
_title5XX = "5XX"
52+
_titleEnvironment = "env"
53+
_titleAPI = "api"
54+
_titleStatus = "status"
55+
_titleUpToDate = "up-to-date"
56+
_titleStale = "stale"
57+
_titleRequested = "requested"
58+
_titleFailed = "failed"
59+
_titleLastupdated = "last update"
60+
_titleAvgRequest = "avg request"
61+
_title2XX = "2XX"
62+
_title4XX = "4XX"
63+
_title5XX = "5XX"
6664
)
6765

6866
var (
@@ -148,11 +146,8 @@ func getAPIsInAllEnvironments() (string, error) {
148146
}
149147

150148
var allSyncAPIs []schema.SyncAPI
151-
var allAPISplitters []schema.APISplitter
152-
var allEnvsSyncAPI []string
153-
var allEnvsAPISplitter []string
149+
var allEnvs []string
154150
errorsMap := map[string]error{}
155-
// get apis from both environments
156151
for _, env := range cliConfig.Environments {
157152
var apisRes schema.GetAPIsResponse
158153
var err error
@@ -164,35 +159,34 @@ func getAPIsInAllEnvironments() (string, error) {
164159

165160
if err == nil {
166161
for range apisRes.SyncAPIs {
167-
allEnvsSyncAPI = append(allEnvsSyncAPI, env.Name)
168-
}
169-
for range apisRes.APISplitter {
170-
allEnvsAPISplitter = append(allEnvsAPISplitter, env.Name)
162+
allEnvs = append(allEnvs, env.Name)
171163
}
164+
172165
allSyncAPIs = append(allSyncAPIs, apisRes.SyncAPIs...)
173-
if env.Provider == types.AWSProviderType {
174-
allAPISplitters = append(allAPISplitters, apisRes.APISplitter...)
175-
}
176166
} else {
177167
errorsMap[env.Name] = err
178168
}
179169
}
180170

181171
out := ""
182-
var apiSplitTable table.Table
183-
var syncAPITable table.Table
184172

185-
// build different table depending on kinds that are deployed
186173
if len(allSyncAPIs) == 0 {
187-
apiSplitTable = apiSplitterListTable(allAPISplitters, allEnvsAPISplitter)
188-
out = apiSplitTable.MustFormat()
189-
} else if len(allAPISplitters) == 0 {
190-
syncAPITable = apiTable(allSyncAPIs, allEnvsSyncAPI)
191-
out = syncAPITable.MustFormat()
174+
if len(errorsMap) == 1 {
175+
// Print the error if there is just one
176+
exit.Error(errors.FirstErrorInMap(errorsMap))
177+
}
178+
// if all envs errored, skip it "no apis are deployed" since it's misleading
179+
if len(errorsMap) != len(cliConfig.Environments) {
180+
out += console.Bold("no apis are deployed") + "\n"
181+
}
192182
} else {
193-
apiSplitTable = apiSplitterListTable(allAPISplitters, allEnvsAPISplitter)
194-
syncAPITable = apiTable(allSyncAPIs, allEnvsSyncAPI)
195-
out = syncAPITable.MustFormat() + "\n" + apiSplitTable.MustFormat()
183+
t := apiTable(allSyncAPIs, allEnvs)
184+
185+
if strset.New(allEnvs...).IsEqual(strset.New(types.LocalProviderType.String())) {
186+
hideReplicaCountColumns(&t)
187+
}
188+
189+
out += t.MustFormat()
196190
}
197191

198192
if len(errorsMap) == 1 {
@@ -235,7 +229,7 @@ func getAPIs(env cliconfig.Environment, printEnv bool) (string, error) {
235229
}
236230
}
237231

238-
if len(apisRes.SyncAPIs) == 0 && len(apisRes.APISplitter) == 0 {
232+
if len(apisRes.SyncAPIs) == 0 {
239233
return console.Bold("no apis are deployed"), nil
240234
}
241235

@@ -244,30 +238,14 @@ func getAPIs(env cliconfig.Environment, printEnv bool) (string, error) {
244238
envNames = append(envNames, env.Name)
245239
}
246240

247-
var apiSplitTable table.Table
248-
var syncAPITable table.Table
249-
var out string
241+
t := apiTable(apisRes.SyncAPIs, envNames)
250242

251-
// build different table depending on kinds that are deployed
252-
if len(apisRes.SyncAPIs) == 0 {
253-
apiSplitTable = apiSplitterListTable(apisRes.APISplitter, envNames)
254-
apiSplitTable.FindHeaderByTitle(_titleEnvironment).Hidden = true
255-
out = apiSplitTable.MustFormat()
256-
} else if len(apisRes.APISplitter) == 0 {
257-
syncAPITable = apiTable(apisRes.SyncAPIs, envNames)
258-
syncAPITable.FindHeaderByTitle(_titleEnvironment).Hidden = true
259-
out = syncAPITable.MustFormat()
260-
} else {
261-
apiSplitTable = apiSplitterListTable(apisRes.APISplitter, envNames)
262-
syncAPITable = apiTable(apisRes.SyncAPIs, envNames)
263-
apiSplitTable.FindHeaderByTitle(_titleEnvironment).Hidden = true
264-
syncAPITable.FindHeaderByTitle(_titleEnvironment).Hidden = true
265-
out = syncAPITable.MustFormat() + "\n" + apiSplitTable.MustFormat()
266-
}
243+
t.FindHeaderByTitle(_titleEnvironment).Hidden = true
244+
245+
out := t.MustFormat()
267246

268247
if env.Provider == types.LocalProviderType {
269-
// apisplitter not supported in local
270-
hideReplicaCountColumns(&syncAPITable)
248+
hideReplicaCountColumns(&t)
271249
mismatchedVersionAPIsErrorMessage, _ := getLocalVersionMismatchedAPIsMessage()
272250
if len(mismatchedVersionAPIsErrorMessage) > 0 {
273251
out += "\n" + mismatchedVersionAPIsErrorMessage
@@ -314,111 +292,7 @@ func getAPI(env cliconfig.Environment, apiName string) (string, error) {
314292
return "", err
315293
}
316294
}
317-
if apiRes.SyncAPI != nil {
318-
return syncAPITable(apiRes.SyncAPI, env)
319-
}
320-
if apiRes.APISplitter != nil {
321-
return apiSplitterTable(apiRes.APISplitter, env)
322-
}
323-
return "", nil
324-
}
325-
326-
func apiSplitterTable(apiSplitter *schema.APISplitter, env cliconfig.Environment) (string, error) {
327-
var out string
328-
329-
lastUpdated := time.Unix(apiSplitter.Spec.LastUpdated, 0)
330-
out += console.Bold("kind: ") + apiSplitter.Spec.Kind.String() + "\n\n"
331-
out += console.Bold("last updated: ") + libtime.SinceStr(&lastUpdated) + "\n\n"
332-
333-
t, err := trafficSplitTable(*apiSplitter, env)
334-
if err != nil {
335-
return "", err
336-
}
337-
t.FindHeaderByTitle(_titleEnvironment).Hidden = true
338-
339-
out += t.MustFormat()
340-
341-
apiEndpoint := apiSplitter.BaseURL
342-
if env.Provider == types.AWSProviderType {
343-
apiEndpoint = urls.Join(apiSplitter.BaseURL, *apiSplitter.Spec.Networking.Endpoint)
344-
if apiSplitter.Spec.Networking.APIGateway == userconfig.NoneAPIGatewayType {
345-
apiEndpoint = strings.Replace(apiEndpoint, "https://", "http://", 1)
346-
}
347-
}
348-
349-
out += "\n" + console.Bold("endpoint: ") + apiEndpoint
350-
351-
out += fmt.Sprintf("\n%s curl %s -X POST -H \"Content-Type: application/json\" -d @sample.json\n", console.Bold("curl:"), apiEndpoint)
352-
353-
out += titleStr("configuration") + strings.TrimSpace(apiSplitter.Spec.UserStr(env.Provider))
354-
355-
return out, nil
356-
}
357-
358-
func trafficSplitTable(apiSplitter schema.APISplitter, env cliconfig.Environment) (table.Table, error) {
359-
rows := make([][]interface{}, 0, len(apiSplitter.Spec.APIs))
360-
361-
for _, api := range apiSplitter.Spec.APIs {
362-
apiRes, err := cluster.GetAPI(MustGetOperatorConfig(env.Name), api.Name)
363-
if err != nil {
364-
return table.Table{}, err
365-
}
366-
lastUpdated := time.Unix(apiRes.SyncAPI.Spec.LastUpdated, 0)
367-
rows = append(rows, []interface{}{
368-
env.Name,
369-
apiRes.SyncAPI.Spec.Name,
370-
api.Weight,
371-
apiRes.SyncAPI.Status.Message(),
372-
apiRes.SyncAPI.Status.Requested,
373-
libtime.SinceStr(&lastUpdated),
374-
latencyStr(&apiRes.SyncAPI.Metrics),
375-
code2XXStr(&apiRes.SyncAPI.Metrics),
376-
code5XXStr(&apiRes.SyncAPI.Metrics),
377-
})
378-
}
379-
380-
return table.Table{
381-
Headers: []table.Header{
382-
{Title: _titleEnvironment},
383-
{Title: _titleAPIs},
384-
{Title: _apiSplitterWeights},
385-
{Title: _titleStatus},
386-
{Title: _titleRequested},
387-
{Title: _titleLastupdated},
388-
{Title: _titleAvgRequest},
389-
{Title: _title2XX},
390-
{Title: _title5XX},
391-
},
392-
Rows: rows,
393-
}, nil
394-
}
395-
396-
func apiSplitterListTable(apiSplitter []schema.APISplitter, envNames []string) table.Table {
397-
rows := make([][]interface{}, 0, len(apiSplitter))
398-
for i, splitAPI := range apiSplitter {
399-
lastUpdated := time.Unix(splitAPI.Spec.LastUpdated, 0)
400-
var apis []string
401-
for _, api := range splitAPI.Spec.APIs {
402-
apis = append(apis, api.Name+":"+s.Int(api.Weight))
403-
}
404-
apisStr := s.TruncateEllipses(strings.Join(apis, " "), 100)
405-
rows = append(rows, []interface{}{
406-
envNames[i],
407-
splitAPI.Spec.Name,
408-
apisStr,
409-
libtime.SinceStr(&lastUpdated),
410-
})
411-
}
412-
413-
return table.Table{
414-
Headers: []table.Header{
415-
{Title: _titleEnvironment},
416-
{Title: _titleAPISplitter},
417-
{Title: _titleAPIs},
418-
{Title: _titleLastupdated},
419-
},
420-
Rows: rows,
421-
}
295+
return syncAPITable(apiRes.SyncAPI, env)
422296
}
423297

424298
func syncAPITable(syncAPI *schema.SyncAPI, env cliconfig.Environment) (string, error) {
@@ -428,8 +302,6 @@ func syncAPITable(syncAPI *schema.SyncAPI, env cliconfig.Environment) (string, e
428302
t.FindHeaderByTitle(_titleEnvironment).Hidden = true
429303
t.FindHeaderByTitle(_titleAPI).Hidden = true
430304

431-
out += console.Bold("kind: ") + syncAPI.Spec.Kind.String() + "\n\n"
432-
433305
out += t.MustFormat()
434306

435307
if env.Provider != types.LocalProviderType && syncAPI.Spec.Monitoring != nil {
@@ -468,6 +340,7 @@ func syncAPITable(syncAPI *schema.SyncAPI, env cliconfig.Environment) (string, e
468340

469341
func apiTable(syncAPIs []schema.SyncAPI, envNames []string) table.Table {
470342
rows := make([][]interface{}, 0, len(syncAPIs))
343+
471344
var totalFailed int32
472345
var totalStale int32
473346
var total4XX int

pkg/lib/k8s/virtual_service.go

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,17 @@ var _virtualServiceTypeMeta = kmeta.TypeMeta{
3333
}
3434

3535
type VirtualServiceSpec struct {
36-
Name string
37-
Gateways []string
38-
Destinations []Destination
39-
Path string
40-
Rewrite *string
41-
Labels map[string]string
42-
Annotations map[string]string
43-
}
44-
45-
type Destination struct {
36+
Name string
37+
Gateways []string
4638
ServiceName string
47-
Weight int32
48-
Port uint32
39+
ServicePort int32
40+
Path string
41+
Rewrite *string
42+
Labels map[string]string
43+
Annotations map[string]string
4944
}
5045

5146
func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualService {
52-
destinations := []*istionetworking.HTTPRouteDestination{}
53-
for _, destination := range spec.Destinations {
54-
destinations = append(destinations, &istionetworking.HTTPRouteDestination{
55-
Destination: &istionetworking.Destination{
56-
Host: destination.ServiceName,
57-
Port: &istionetworking.PortSelector{
58-
Number: destination.Port,
59-
},
60-
},
61-
Weight: destination.Weight,
62-
})
63-
}
64-
6547
virtualService := &istioclientnetworking.VirtualService{
6648
TypeMeta: _virtualServiceTypeMeta,
6749
ObjectMeta: kmeta.ObjectMeta{
@@ -83,7 +65,16 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ
8365
},
8466
},
8567
},
86-
Route: destinations,
68+
Route: []*istionetworking.HTTPRouteDestination{
69+
{
70+
Destination: &istionetworking.Destination{
71+
Host: spec.ServiceName,
72+
Port: &istionetworking.PortSelector{
73+
Number: uint32(spec.ServicePort),
74+
},
75+
},
76+
},
77+
},
8778
},
8879
},
8980
},

pkg/operator/endpoints/logs.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"net/http"
2121

2222
"github.com/cortexlabs/cortex/pkg/operator/resources"
23-
"github.com/cortexlabs/cortex/pkg/types/userconfig"
2423
"github.com/gorilla/mux"
2524
"github.com/gorilla/websocket"
2625
)
@@ -33,14 +32,11 @@ func ReadLogs(w http.ResponseWriter, r *http.Request) {
3332
respondError(w, r, err)
3433
return
3534
}
35+
3636
if deployedResource == nil {
3737
respondError(w, r, resources.ErrorAPINotDeployed(apiName))
3838
return
3939
}
40-
if deployedResource.Kind != userconfig.SyncAPIKind {
41-
respondError(w, r, resources.ErrorOperationNotSupportedForKind(deployedResource.Kind))
42-
return
43-
}
4440

4541
upgrader := websocket.Upgrader{}
4642
socket, err := upgrader.Upgrade(w, r, nil)

0 commit comments

Comments
 (0)