Skip to content

Commit

Permalink
Merge pull request #97 from OpsLevel/kr/update-timeout
Browse files Browse the repository at this point in the history
update opslevel-go to latest and increase timeout
  • Loading branch information
rocktavious authored Jul 18, 2023
2 parents 5e1dbe8 + 4927ae4 commit 3a4a105
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20230718-161036.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: Increase timeout on graphql requests to 60s
time: 2023-07-18T16:10:36.986992-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20230718-160958.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: Upgrade opslevel-go to 2023.7.17
time: 2023-07-18T16:09:58.960308-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20230718-161015.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: Convert to using opslevel.ID
time: 2023-07-18T16:10:15.610849-05:00
26 changes: 13 additions & 13 deletions src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"sync"
"time"

"github.com/opslevel/opslevel-go/v2022"
"github.com/opslevel/opslevel-go/v2023"
"github.com/opslevel/opslevel-runner/pkg"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -54,29 +54,29 @@ func doRun(cmd *cobra.Command, args []string) {
k8sClient := clientset.NewForConfigOrDie(config)

log.Info().Msgf("electing leader...")
go electLeader(k8sClient, runner.Id.(string))
go electLeader(k8sClient, runner.Id)
}

log.Info().Msgf("Starting runner for id '%s'", runner.Id)
pkg.StartMetricsServer(runner.Id.(string), viper.GetInt("metrics-port"))
pkg.StartMetricsServer(runner.Id, viper.GetInt("metrics-port"))
stop := opslevel_common.InitSignalHandler()
wg := startWorkers(runner.Id.(string), stop)
wg := startWorkers(runner.Id, stop)
<-stop // Enter Forever Loop
log.Info().Msgf("interupt - waiting for jobs to complete ...")
wg.Wait()
log.Info().Msgf("Unregister runner for id '%s'...", runner.Id)
client.RunnerUnregister(&runner.Id)
client.RunnerUnregister(runner.Id)
}

func electLeader(k8sClient *clientset.Clientset, runnerId string) {
func electLeader(k8sClient *clientset.Clientset, runnerId opslevel.ID) {
leaseLockName := viper.GetString("runner-deployment")
leaseLockNamespace := viper.GetString("runner-pod-namespace")
lockIdentity := viper.GetString("runner-pod-name")

pkg.RunLeaderElection(k8sClient, runnerId, leaseLockName, lockIdentity, leaseLockNamespace)
}

func startWorkers(runnerId string, stop <-chan struct{}) *sync.WaitGroup {
func startWorkers(runnerId opslevel.ID, stop <-chan struct{}) *sync.WaitGroup {
wg := sync.WaitGroup{}
concurrency := getConcurrency()
wg.Add(concurrency)
Expand All @@ -96,7 +96,7 @@ func getConcurrency() int {
return concurrency
}

func jobWorker(wg *sync.WaitGroup, index int, runnerId string, jobQueue <-chan opslevel.RunnerJob) {
func jobWorker(wg *sync.WaitGroup, index int, runnerId opslevel.ID, jobQueue <-chan opslevel.RunnerJob) {
logMaxBytes := viper.GetInt("job-pod-log-max-size")
logMaxDuration := time.Duration(viper.GetInt("job-pod-log-max-interval")) * time.Second
logPrefix := func() string { return fmt.Sprintf("%s [%d] ", time.Now().UTC().Format(time.RFC3339), index) }
Expand All @@ -112,7 +112,7 @@ func jobWorker(wg *sync.WaitGroup, index int, runnerId string, jobQueue <-chan o
defer wg.Done()
for job := range jobQueue {
ctx := context.Background()
jobId := job.Id.(string)
jobId := job.Id
jobNumber := job.Number()

streamer := pkg.NewLogStreamer(
Expand Down Expand Up @@ -174,10 +174,10 @@ func jobWorker(wg *sync.WaitGroup, index int, runnerId string, jobQueue <-chan o
logger.Info().Msgf("Shutting down job processor %d ...", index)
}

func jobPoller(runnerId string, stop <-chan struct{}, jobQueue chan<- opslevel.RunnerJob) {
func jobPoller(runnerId opslevel.ID, stop <-chan struct{}, jobQueue chan<- opslevel.RunnerJob) {
logger := log.With().Int("worker", 0).Logger()
client := pkg.NewGraphClient()
token := opslevel.NewID("")
token := opslevel.ID("")
poll_wait_time := time.Second * time.Duration(viper.GetInt("poll-interval"))
logger.Info().Msg("Starting polling for jobs")
for {
Expand All @@ -190,14 +190,14 @@ func jobPoller(runnerId string, stop <-chan struct{}, jobQueue chan<- opslevel.R
logger.Trace().Msg("Polling for jobs ...")
continue_polling := true
for continue_polling {
logger.Debug().Msgf("Get pending jobs with lastUpdateToken '%v' ...", *token)
logger.Debug().Msgf("Get pending jobs with lastUpdateToken '%v' ...", token)
job, nextToken, err := client.RunnerGetPendingJob(runnerId, token)
if err != nil {
logger.Error().Err(err).Msg("got error when getting pending job")
continue_polling = false
} else {
token = nextToken
if job.Id == nil {
if job.Id == "" {
continue_polling = false
} else {
logger.Debug().Msgf("Enqueuing job '%s'", job.Number())
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"fmt"
"github.com/opslevel/opslevel-go/v2022"
"github.com/opslevel/opslevel-go/v2023"
"github.com/opslevel/opslevel-runner/pkg"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -31,7 +31,7 @@ func doTest(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if job.Id == nil {
if job.Id == "" {
job.Id = "1"
}
streamer := pkg.NewLogStreamer(
Expand Down
33 changes: 18 additions & 15 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require (
github.com/getsentry/sentry-go v0.21.0
github.com/go-resty/resty/v2 v2.7.0
github.com/opslevel/opslevel-common/v2022 v2022.6.28
github.com/opslevel/opslevel-go/v2022 v2022.10.22
github.com/opslevel/opslevel-go/v2023 v2023.7.17
github.com/prometheus/client_golang v1.14.0
github.com/rocktavious/autopilot v0.1.5
github.com/rs/zerolog v1.28.0
github.com/rs/zerolog v1.29.1
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
go.opentelemetry.io/otel v1.15.1
Expand All @@ -20,7 +20,7 @@ require (
)

require (
cloud.google.com/go/compute v1.14.0 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
Expand All @@ -42,19 +42,22 @@ require (
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gosimple/slug v1.13.1 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hasura/go-graphql-client v0.9.3 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -69,32 +72,32 @@ require (
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/relvacode/iso8601 v1.1.0 // indirect
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 // indirect
github.com/relvacode/iso8601 v1.3.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.29.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
nhooyr.io/websocket v1.8.7 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/opslevel/opslevel-go/v2022 => ./submodules/opslevel-go
replace github.com/opslevel/opslevel-go/v2023 => ./submodules/opslevel-go
Loading

0 comments on commit 3a4a105

Please sign in to comment.