• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tensorchord / openmodelz / 6180409240

14 Sep 2023 03:02AM UTC coverage: 26.069% (-3.9%) from 29.927%
6180409240

push

github

web-flow
feat: Support BYOC (#171)

Signed-off-by: xieydd <xieydd@gmail.com>

443 of 443 new or added lines in 14 files covered. (100.0%)

939 of 3602 relevant lines covered (26.07%)

1.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/agent/pkg/server/server_websocket.go
1
package server
2

3
import (
4
        "context"
5
        "net/http"
6
        "net/url"
7
        "time"
8

9
        "github.com/rancher/remotedialer"
10
        "github.com/sirupsen/logrus"
11
        "github.com/tensorchord/openmodelz/agent/api/types"
12
)
13

14
func (s *Server) connect(apiServerReady <-chan struct{}) {
×
15
        <-apiServerReady
×
16
        var clusterDialEndpoint string
×
17
        headers := http.Header{
×
18
                "X-Cluster-ID": {s.config.ModelZCloud.ID},
×
19
                "Agent-Token":  {s.config.ModelZCloud.AgentToken},
×
20
        }
×
21
        u, err := url.Parse(s.config.ModelZCloud.URL)
×
22
        if err != nil {
×
23
                logrus.Errorf("failed to parse url: %v", err)
×
24
        }
×
25

26
        switch u.Scheme {
×
27
        case "http":
×
28
                clusterDialEndpoint = "ws://" + u.Host + types.DailEndPointSuffix
×
29
        case "https":
×
30
                clusterDialEndpoint = "wss://" + u.Host + types.DailEndPointSuffix
×
31
        }
32

33
        ctx := context.Background()
×
34
        go func() {
×
35
                for {
×
36
                        remotedialer.ClientConnect(ctx, clusterDialEndpoint, headers, nil, func(proto, address string) bool { return true }, nil)
×
37
                        select {
×
38
                        case <-ctx.Done():
×
39
                                return
×
40
                        case <-time.After(s.config.ModelZCloud.HeartbeatInterval):
×
41
                                // retry connect after interval
42
                        }
43
                }
44
        }()
45

46
        // retry(
47
        //         s.config.ModelZCloud.HeartbeatInterval,
48
        //         func() error {
49
        //                 logrus.Debugf("run websocket server")
50
        //                 ctx := context.Background()
51
        //                 err := remotedialer.ClientConnect(ctx, clusterDialEndpoint, headers, nil,
52
        //                         func(proto, address string) bool { return true }, nil)
53
        //                 if err != nil {
54
        //                         logrus.Errorf("failed to connect to apiserver: %v", err)
55
        //                         return err
56
        //                 }
57
        //                 return nil
58
        //         },
59
        // )
60

61
}
62

63
func retry(sleep time.Duration, f func() error) {
×
64
        i := 1
×
65
        for {
×
66
                err := f()
×
67
                if err == nil {
×
68
                        return
×
69
                } else {
×
70
                        logrus.Errorf("retry %d times, still failed", i)
×
71
                        time.Sleep(sleep)
×
72
                        i++
×
73
                }
×
74
        }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc