Skip to content

Commit

Permalink
Merge branch 'master' into fix_619
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Nov 14, 2019
2 parents baf8872 + c8f6e3e commit b3f594b
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 36 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test
on: [push]
jobs:
build:
name: Test
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Get dependencies
run: go get -v -t -d ./...

- name: Test without docker
run: go test -v -timeout 200s ./...

9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12
FROM golang:1.13
LABEL maintainer="Victor Castell <victor@victorcastell.com>"

EXPOSE 8080 8946
Expand All @@ -12,6 +12,6 @@ COPY go.sum go.sum
RUN go mod download

COPY . .
RUN go install ./...
#RUN go install ./...

CMD ["dkron"]
#CMD ["dkron"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img width="400" src="docs/images/DKRON_STICKER_OK_CMYK_RGB_CONV_300.png" alt="Dkron" title="Dkron" />
</p>

# Dkron - Distributed, fault tolerant job scheduling system for cloud native environments [![GoDoc](https://godoc.org/github.com/distribworks/dkron?status.svg)](https://godoc.org/github.com/distribworks/dkron) [![Build Status](https://travis-ci.org/distribworks/dkron.svg?branch=master)](https://travis-ci.org/distribworks/dkron) [![Gitter](https://badges.gitter.im/distribworks/dkron.svg)](https://gitter.im/distribworks/dkron)
# Dkron - Distributed, fault tolerant job scheduling system for cloud native environments [![GoDoc](https://godoc.org/github.com/distribworks/dkron?status.svg)](https://godoc.org/github.com/distribworks/dkron) [![Actions Status](https://github.com/distribworks/dkron/workflows/test/badge.svg)](https://github.com/distribworks/dkron/actions) [![Gitter](https://badges.gitter.im/distribworks/dkron.svg)](https://gitter.im/distribworks/dkron)

Website: http://dkron.io/

Expand Down
2 changes: 2 additions & 0 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func NewAgent(config *Config, options ...AgentOption) *Agent {
// Start the current agent by running all the necessary
// checks and server or client routines.
func (a *Agent) Start() error {
InitLogger(a.config.LogLevel, a.config.NodeName)

// Normalize configured addresses
a.config.normalizeAddrs()

Expand Down
31 changes: 31 additions & 0 deletions dkron/agent_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package dkron

import (
"io/ioutil"
"os"
"testing"
"time"

"github.com/hashicorp/serf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
logLevel = "error"
)

func TestAgentCommand_runForElection(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

a1Name := "test1"
a2Name := "test2"
a1Addr := testutil.GetBindAddr().String()
Expand All @@ -32,6 +39,7 @@ func TestAgentCommand_runForElection(t *testing.T) {
c.LogLevel = logLevel
c.BootstrapExpect = 3
c.DevMode = true
c.DataDir = dir

a1 := NewAgent(c)
if err := a1.Start(); err != nil {
Expand All @@ -57,6 +65,7 @@ func TestAgentCommand_runForElection(t *testing.T) {
c.LogLevel = logLevel
c.BootstrapExpect = 3
c.DevMode = true
c.DataDir = dir

a2 := NewAgent(c)
a2.Start()
Expand All @@ -70,6 +79,7 @@ func TestAgentCommand_runForElection(t *testing.T) {
c.LogLevel = logLevel
c.BootstrapExpect = 3
c.DevMode = true
c.DataDir = dir

a3 := NewAgent(c)
a3.Start()
Expand All @@ -89,6 +99,10 @@ func TestAgentCommand_runForElection(t *testing.T) {
}

func Test_processFilteredNodes(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

a1Addr := testutil.GetBindAddr().String()
a2Addr := testutil.GetBindAddr().String()

Expand All @@ -100,6 +114,7 @@ func Test_processFilteredNodes(t *testing.T) {
c.LogLevel = logLevel
c.Tags = map[string]string{"tag": "test"}
c.DevMode = true
c.DataDir = dir

a1 := NewAgent(c)
a1.Start()
Expand All @@ -118,6 +133,7 @@ func Test_processFilteredNodes(t *testing.T) {
"extra": "tag",
}
c.DevMode = true
c.DataDir = dir

a2 := NewAgent(c)
a2.Start()
Expand Down Expand Up @@ -146,6 +162,10 @@ func Test_processFilteredNodes(t *testing.T) {
}

func TestEncrypt(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

c := DefaultConfig()
c.BindAddr = testutil.GetBindAddr().String()
c.NodeName = "test1"
Expand All @@ -154,6 +174,7 @@ func TestEncrypt(t *testing.T) {
c.EncryptKey = "kPpdjphiipNSsjd4QHWbkA=="
c.LogLevel = logLevel
c.DevMode = true
c.DataDir = dir

a := NewAgent(c)
a.Start()
Expand All @@ -165,6 +186,10 @@ func TestEncrypt(t *testing.T) {
}

func Test_getRPCAddr(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

a1Addr := testutil.GetBindAddr()

c := DefaultConfig()
Expand All @@ -174,6 +199,7 @@ func Test_getRPCAddr(t *testing.T) {
c.Tags = map[string]string{"role": "test"}
c.LogLevel = logLevel
c.DevMode = true
c.DataDir = dir

a := NewAgent(c)
a.Start()
Expand All @@ -188,12 +214,17 @@ func Test_getRPCAddr(t *testing.T) {
}

func TestAgentConfig(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

advAddr := testutil.GetBindAddr().String()

c := DefaultConfig()
c.BindAddr = testutil.GetBindAddr().String()
c.AdvertiseAddr = advAddr
c.LogLevel = logLevel
c.DataDir = dir

a := NewAgent(c)
a.Start()
Expand Down
2 changes: 1 addition & 1 deletion dkron/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestAPIJobCreateUpdateValidationBadConcurrency(t *testing.T) {
"schedule": "@every 1m",
"executor": "shell",
"executor_config": {"command": "date"},
"concurrency": "badvalue"
"concurrency": "badvalue",
"disabled": true
}`))

Expand Down
14 changes: 11 additions & 3 deletions dkron/grpc_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package dkron

import (
"io/ioutil"
"os"
"testing"
"time"

"github.com/hashicorp/serf/testutil"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestGRPCExecutionDone(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

viper.Reset()

aAddr := testutil.GetBindAddr().String()
Expand All @@ -21,6 +28,7 @@ func TestGRPCExecutionDone(t *testing.T) {
c.LogLevel = logLevel
c.BootstrapExpect = 1
c.DevMode = true
c.DataDir = dir

a := NewAgent(c)
a.Start()
Expand All @@ -34,9 +42,9 @@ func TestGRPCExecutionDone(t *testing.T) {

testJob := &Job{
Name: "test",
Schedule: "@every 1m",
Schedule: "@manually",
Executor: "shell",
ExecutorConfig: map[string]string{"command": "/bin/false"},
ExecutorConfig: map[string]string{"command": "/bin/true"},
Disabled: true,
}

Expand Down Expand Up @@ -65,7 +73,7 @@ func TestGRPCExecutionDone(t *testing.T) {
a.Store.DeleteJob(testJob.Name)

testExecution.FinishedAt = time.Now()
err := rc.ExecutionDone(a.getRPCAddr(), testExecution)
err = rc.ExecutionDone(a.getRPCAddr(), testExecution)

assert.Error(t, err, ErrExecutionDoneForDeletedJob)
}
9 changes: 4 additions & 5 deletions dkron/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ const (
// MaxExecutions to maintain in the storage
MaxExecutions = 100

defaultUpdateMaxAttempts = 5
defaultGCInterval = 5 * time.Minute
defaultGCDiscardRatio = 0.7
defaultGCInterval = 5 * time.Minute
defaultGCDiscardRatio = 0.7
)

var (
Expand All @@ -47,8 +46,8 @@ type JobOptions struct {

// NewStore creates a new Storage instance.
func NewStore(a *Agent, dir string) (*Store, error) {
opts := badger.DefaultOptions(dir)
opts.Logger = log
opts := badger.DefaultOptions(dir).
WithLogger(log)

db, err := badger.Open(opts)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da
github.com/aws/aws-sdk-go v1.16.23 // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/dgraph-io/badger/v2 v2.0.0-rc4
github.com/dgraph-io/badger/v2 v2.0.0
github.com/dnaeon/go-vcr v1.0.1 // indirect
github.com/gin-contrib/expvar v0.0.0-20180827025536-251166f58ff2
github.com/gin-contrib/multitemplate v0.0.0-20170922032617-bbc6daf6024b
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ github.com/denverdino/aliyungo v0.0.0-20170926055100-d3308649c661 h1:lrWnAyy/F72
github.com/denverdino/aliyungo v0.0.0-20170926055100-d3308649c661/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0=
github.com/dgraph-io/badger/v2 v2.0.0-rc4 h1:SEdIJ58VRyWaeyUREe8M59PSLlF6mm3IBW0hWfLIa1Q=
github.com/dgraph-io/badger/v2 v2.0.0-rc4/go.mod h1:YoRSIp1LmAJ7zH7tZwRvjNMUYLxB4wl3ebYkaIruZ04=
github.com/dgraph-io/badger/v2 v2.0.0 h1:Cr05o2TUd2IcLbEY0aGd8mbjm1YyQpy+dswo3BcDXrE=
github.com/dgraph-io/badger/v2 v2.0.0/go.mod h1:YoRSIp1LmAJ7zH7tZwRvjNMUYLxB4wl3ebYkaIruZ04=
github.com/dgraph-io/ristretto v0.0.0-20191025175511-c1f00be0418e h1:aeUNgwup7PnDOBAD1BOKAqzb/W/NksOj6r3dwKKuqfg=
github.com/dgraph-io/ristretto v0.0.0-20191025175511-c1f00be0418e/go.mod h1:edzKIzGvqUCMzhTVWbiTSe75zD9Xxq0GtSBtFmaUTZs=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
Expand Down
12 changes: 0 additions & 12 deletions scripts/.validate
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#!/bin/bash

for i in {1..100}
do
curl localhost:8080/v1/jobs -d "{
\"name\": \"test_job_$i\",
\"schedule\": \"@every 10s\",
\"executor\": \"shell\",
\"executor_config\": {
\"command\": \"echo $1\"
}
}"
done

if [ -z "$VALIDATE_UPSTREAM" ]; then
# this is kind of an expensive check, so let's not do this twice if we
# are running more than one validate bundlescript
Expand Down
2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e
docker build -t dkron .
docker run dkron scripts/validate-gofmt
docker run dkron go vet
docker run --rm dkron go test -v -timeout 120s ./... $1
docker run --rm dkron go test -v ./... $1

0 comments on commit b3f594b

Please sign in to comment.