Skip to content

Commit

Permalink
feat: working
Browse files Browse the repository at this point in the history
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
  • Loading branch information
QuentinN42 committed Jan 30, 2025
1 parent ae123c1 commit 7ca62d5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ go-repeater
main
.vscode
.idea
__*
._*
.env
12 changes: 6 additions & 6 deletions cmd/repeater/repeater.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/Escape-Technologies/repeater/pkg/kube"
"github.com/Escape-Technologies/repeater/pkg/logger"
"github.com/Escape-Technologies/repeater/pkg/roundtrip"
"github.com/Escape-Technologies/repeater/pkg/stream"

_ "net/http/pprof"
)
Expand Down Expand Up @@ -155,15 +156,14 @@ func main() {
go pprof()
go startHealth()

// proxyURL := setupProxyURL()
proxyURL := setupProxyURL()
ap := getAutoprovisioner()
// repeaterId := getRepeaterId(ctx, ap)
// url := setupHTTPClients()
repeaterId := getRepeaterId(ctx, ap)
url := setupHTTPClients()

logger.Info("Starting repeater client...")

// go logger.AlwaysConnect(url, repeaterId, proxyURL)
isConnected.Store(true)
go logger.AlwaysConnect(url, repeaterId, proxyURL)
kube.AlwaysConnectAndRun(ctx, ap, isConnected)
// stream.AlwaysConnectAndRun(url, repeaterId, isConnected, proxyURL)
stream.AlwaysConnectAndRun(url, repeaterId, isConnected, proxyURL)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.5
toolchain go1.23.4

require (
github.com/Escape-Technologies/cli v0.0.10
github.com/Escape-Technologies/cli v0.0.12
github.com/google/uuid v1.6.0
github.com/pixelbender/go-traceroute v0.0.0-20190414152342-e631ab553a80
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Escape-Technologies/cli v0.0.10 h1:5OaeOgcMYJzxAkiWtQCm1zVQqO6zKQQ0n8Kl3nwp1l0=
github.com/Escape-Technologies/cli v0.0.10/go.mod h1:rDuGAj9YD2x2gA+GBbd23noKS7XK09MaoFST/D+odSE=
github.com/Escape-Technologies/cli v0.0.12 h1:k4kmbSG/TKCVTHyXtqXWi2kDCXblU31JKlsZeCYUi2Y=
github.com/Escape-Technologies/cli v0.0.12/go.mod h1:rDuGAj9YD2x2gA+GBbd23noKS7XK09MaoFST/D+odSE=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
Expand Down
35 changes: 4 additions & 31 deletions pkg/autoprovisioning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,37 +82,16 @@ func (a *Autoprovisioner) getId(ctx context.Context) (string, error) {
if err != nil {
return "", err
}
if location.JSON200 == nil {
if location.StatusCode() != 200 || location.JSON200 == nil {
logger.Debug("API error: %d", location.StatusCode())
logger.Debug(string(location.Body))

Check failure on line 87 in pkg/autoprovisioning/main.go

View workflow job for this annotation

GitHub Actions / Lint (golangci-lint)

printf: non-constant format string in call to github.com/Escape-Technologies/repeater/pkg/logger.Debug (govet)
return "", errors.New("no location created")
}
a.locationId = location.JSON200.Id
logger.Info("New repeater created with name %s", a.repeaterName)
return a.locationId.String(), nil
}

func printException(exception interface{}) {
ex, ok := exception.(struct {
Name string
Message string
})
if ok {
logger.Debug("API error: %s : ", ex.Name, ex.Message)
}
evts, ok := exception.(struct {
Events []struct {
Logline string
Severity *string
}
})
for _, event := range evts.Events {
s := ""
if event.Severity != nil {
s = *event.Severity
}
logger.Debug("%s %s", s, event.Logline)
}
}

// Create a kubernetes integration if it doesn't exist
func (a *Autoprovisioner) CreateIntegration(ctx context.Context) error {
if a.integrationId != uuid.Nil {
Expand Down Expand Up @@ -158,13 +137,7 @@ func (a *Autoprovisioner) CreateIntegration(ctx context.Context) error {
}
if integration.StatusCode() != 200 || integration.JSON200 == nil {
logger.Debug("API error: %d", integration.StatusCode())
if integration.JSON400 != nil {
printException(integration.JSON400)
} else if integration.JSON500 != nil {
printException(integration.JSON500)
} else {
logger.Debug("Unknown error: %s", string(integration.Body))
}
logger.Debug(string(integration.Body))

Check failure on line 140 in pkg/autoprovisioning/main.go

View workflow job for this annotation

GitHub Actions / Lint (golangci-lint)

printf: non-constant format string in call to github.com/Escape-Technologies/repeater/pkg/logger.Debug (govet)
return errors.New("error creating integration")
}
a.integrationId = integration.JSON200.Id
Expand Down
2 changes: 2 additions & 0 deletions pkg/kube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func provisionIntegrationWithRetry(ctx context.Context, ap *autoprovisioning.Aut
err := ap.CreateIntegration(ctx)
if err == nil {
return nil
} else {
logger.Debug("Error provisioning integration: %v", err)
}
time.Sleep(autoprovisioningRetryInterval)
return provisionIntegrationWithRetry(ctx, ap, count+1)
Expand Down

0 comments on commit 7ca62d5

Please sign in to comment.