Skip to content

Commit 1721cbb

Browse files
committed
Merge branch 'master' into use-duty-types
2 parents 9f7bf93 + 6d8a9f3 commit 1721cbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1523
-333
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- k8s
1818
- datasources
1919
- git
20+
# - restic
2021
runs-on: ubuntu-latest
2122
steps:
2223
- name: Install Go
@@ -35,11 +36,6 @@ jobs:
3536
restore-keys: |
3637
cache-
3738
- run: make bin
38-
- name: Install restic
39-
run: |
40-
sudo apt update
41-
sudo apt install -y restic
42-
sudo restic self-update
4339
- name: Test
4440
env:
4541
KUBERNETES_VERSION: v1.20.7

Dockerfile

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,40 @@ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key
3232
fonts-freefont-ttf \
3333
--no-install-recommends
3434

35+
RUN apt-get update && apt-get upgrade -y && \
36+
rm -Rf /var/lib/apt/lists/* && \
37+
apt-get clean
3538

36-
RUN curl -L https://github.com/restic/restic/releases/download/v0.12.0/restic_0.12.0_linux_amd64.bz2 -o restic.bz2 && \
39+
ENV RESTIC_VERSION=0.15.2
40+
RUN curl -L https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_amd64.bz2 -o restic.bz2 && \
3741
bunzip2 /app/restic.bz2 && \
3842
chmod +x /app/restic && \
3943
mv /app/restic /usr/local/bin/ && \
4044
rm -rf /app/restic.bz2
4145

42-
#Install jmeter
43-
RUN curl -L https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.4.3.zip -o apache-jmeter-5.4.3.zip && \
44-
unzip apache-jmeter-5.4.3.zip -d /opt && \
45-
rm apache-jmeter-5.4.3.zip
46+
ENV JMETER_VERSION=5.5
47+
RUN curl -L https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-${JMETER_VERSION}.zip -o apache-jmeter-${JMETER_VERSION}.zip && \
48+
unzip apache-jmeter-${JMETER_VERSION}.zip -d /opt && \
49+
rm apache-jmeter-${JMETER_VERSION}.zip
4650

47-
ENV PATH /opt/apache-jmeter-5.4.3/bin/:$PATH
51+
ENV PATH /opt/apache-jmeter-${JMETER_VERSION}/bin/:$PATH
4852

4953

5054
RUN curl -L https://github.com/flanksource/askgit/releases/download/v0.4.8-flanksource/askgit-linux-amd64.tar.gz -o askgit.tar.gz && \
5155
tar xf askgit.tar.gz && \
5256
mv askgit /usr/local/bin/askgit && \
53-
rm askgit.tar.gz
57+
rm askgit.tar.gz && \
58+
wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.18_amd64.deb && \
59+
dpkg -i libssl1.1_1.1.1f-1ubuntu2.18_amd64.deb && \
60+
rm libssl1.1_1.1.1f-1ubuntu2.18_amd64.deb
5461

5562
ENV K6_VERSION=v0.44.0
5663
RUN curl -L https://github.com/grafana/k6/releases/download/${K6_VERSION}/k6-${K6_VERSION}-linux-amd64.tar.gz -o k6.tar.gz && \
5764
tar xvf k6.tar.gz && \
5865
mv k6-${K6_VERSION}-linux-amd64/k6 /usr/local/bin/k6 && \
5966
rm k6.tar.gz
6067

61-
RUN curl -Lsf https://sh.benthos.dev | bash -s -- 3.56.0
68+
RUN curl -Lsf https://sh.benthos.dev | bash -s -- 4.15.0
6269

6370
RUN curl -L https://github.com/multiprocessio/dsq/releases/download/v0.23.0/dsq-linux-x64-v0.23.0.zip -o dsq.zip && \
6471
unzip dsq.zip && \

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,16 @@ endif
201201
ln -s apache-jmeter-5.4.3/bin/jmeter .bin/jmeter
202202

203203
.bin/restic:
204-
wget -nv https://github.com/restic/restic/releases/download/v0.12.1/restic_0.12.1_$(OS)_$(ARCH).bz2 -O .bin/restic.bz2 && \
205-
bunzip2 .bin/restic.bz2 && \
206-
chmod +x .bin/restic
204+
curl -sSLo /usr/local/bin/restic.bz2 https://github.com/restic/restic/releases/download/v0.12.1/restic_0.12.1_$(OS)_$(ARCH).bz2 && \
205+
bunzip2 /usr/local/bin/restic.bz2 && \
206+
chmod +x /usr/local/bin/restic
207207

208208
.bin/wait4x:
209209
wget -nv https://github.com/atkrad/wait4x/releases/download/v0.3.0/wait4x-$(OS)-$(ARCH) -O .bin/wait4x && \
210210
chmod +x .bin/wait4x
211211

212212
.bin/karina:
213-
wget -q https://github.com/flanksource/karina/releases/download/v0.50.0/karina_$(OS)-$(ARCH) -O .bin/karina && \
213+
curl -sSLo .bin/karina https://github.com/flanksource/karina/releases/download/v0.50.0/karina_$(OS)-$(ARCH) && \
214214
chmod +x .bin/karina
215215

216216
.bin/yq: .bin
@@ -224,8 +224,11 @@ ifeq ($(OS), darwin)
224224
brew install --cask macfuse
225225
brew install datawire/blackbird/telepresence-legacy
226226
else
227-
sudo curl -fL https://app.getambassador.io/download/tel2/linux/amd64/latest/telepresence -o /usr/local/bin/telepresence
228-
sudo chmod a+x /usr/local/bin/telepresence
227+
sudo apt-get install -y conntrack
228+
wget https://s3.amazonaws.com/datawire-static-files/telepresence/telepresence-0.109.tar.gz
229+
tar xzf telepresence-0.109.tar.gz
230+
sudo mv telepresence-0.109/bin/telepresence /usr/local/bin/
231+
sudo mv telepresence-0.109/libexec/sshuttle-telepresence /usr/local/bin/
229232
endif
230233
endif
231234

api/context/context.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ package context
22

33
import (
44
gocontext "context"
5+
"errors"
56
"fmt"
7+
"strings"
68
"time"
79

810
v1 "github.com/flanksource/canary-checker/api/v1"
911
"github.com/flanksource/commons/logger"
12+
"github.com/flanksource/duty"
13+
"github.com/flanksource/duty/models"
1014
"github.com/flanksource/kommons"
15+
"gorm.io/gorm"
1116
)
1217

1318
type KubernetesContext struct {
@@ -25,6 +30,7 @@ type Context struct {
2530
Canary v1.Canary
2631
Environment map[string]interface{}
2732
logger.Logger
33+
db *gorm.DB
2834
}
2935

3036
func (ctx *Context) String() string {
@@ -41,6 +47,37 @@ func (ctx *Context) WithDeadline(deadline time.Time) (*Context, gocontext.Cancel
4147
return ctx, fn
4248
}
4349

50+
func (ctx *Context) HydrateConnectionByURL(connectionName string) (*models.Connection, error) {
51+
if !strings.HasPrefix(connectionName, "connection://") {
52+
return nil, nil
53+
}
54+
if connectionName == "" {
55+
return nil, nil
56+
}
57+
58+
if ctx.db == nil {
59+
return nil, errors.New("db has not been initialized")
60+
}
61+
62+
k8sClient, err := ctx.Kommons.GetClientset()
63+
if err != nil {
64+
return nil, err
65+
}
66+
67+
connection, err := duty.HydratedConnectionByURL(ctx, ctx.db, k8sClient, ctx.Namespace, connectionName)
68+
if err != nil {
69+
return nil, err
70+
}
71+
72+
// Connection name was explicitly provided but was not found.
73+
// That's an error.
74+
if connection == nil {
75+
return nil, fmt.Errorf("connection %s not found", connectionName)
76+
}
77+
78+
return connection, nil
79+
}
80+
4481
func NewKubernetesContext(client *kommons.Client, namespace string) *KubernetesContext {
4582
if namespace == "" {
4683
namespace = "default"
@@ -64,11 +101,13 @@ func (ctx *KubernetesContext) Clone() *KubernetesContext {
64101
}
65102
}
66103

67-
func New(client *kommons.Client, canary v1.Canary) *Context {
104+
func New(client *kommons.Client, db *gorm.DB, canary v1.Canary) *Context {
68105
if canary.Namespace == "" {
69106
canary.Namespace = "default"
70107
}
108+
71109
return &Context{
110+
db: db,
72111
Context: gocontext.Background(),
73112
Kommons: client,
74113
Namespace: canary.GetNamespace(),
@@ -86,6 +125,18 @@ func (ctx *Context) IsTrace() bool {
86125
return ctx.Canary.IsTrace()
87126
}
88127

128+
func (ctx *Context) Debugf(format string, args ...interface{}) {
129+
if ctx.IsDebug() {
130+
ctx.Logger.Infof(format, args...)
131+
}
132+
}
133+
134+
func (ctx *Context) Tracef(format string, args ...interface{}) {
135+
if ctx.IsTrace() {
136+
ctx.Logger.Infof(format, args...)
137+
}
138+
}
139+
89140
func (ctx *Context) New(environment map[string]interface{}) *Context {
90141
return &Context{
91142
Context: ctx.Context,

api/v1/canary_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type CanarySpec struct {
7272
ConfigDB []ConfigDBCheck `yaml:"configDB,omitempty" json:"configDB,omitempty"`
7373
Elasticsearch []ElasticsearchCheck `yaml:"elasticsearch,omitempty" json:"elasticsearch,omitempty"`
7474
AlertManager []AlertManagerCheck `yaml:"alertmanager,omitempty" json:"alertmanager,omitempty"`
75+
Dynatrace []DynatraceCheck `yaml:"dynatrace,omitempty" json:"dynatrace,omitempty"`
7576
AzureDevops []AzureDevopsCheck `yaml:"azureDevops,omitempty" json:"azureDevops,omitempty"`
7677
// interval (in seconds) to run checks on Deprecated in favor of Schedule
7778
Interval uint64 `yaml:"interval,omitempty" json:"interval,omitempty"`
@@ -191,6 +192,9 @@ func (spec CanarySpec) GetAllChecks() []external.Check {
191192
for _, check := range spec.AzureDevops {
192193
checks = append(checks, check)
193194
}
195+
for _, check := range spec.Dynatrace {
196+
checks = append(checks, check)
197+
}
194198
return checks
195199
}
196200

@@ -205,7 +209,7 @@ func (spec CanarySpec) GetSchedule() string {
205209
}
206210

207211
func (c Canary) IsTrace() bool {
208-
return c.Annotations != nil && c.Annotations["debug"] == "true" //nolint
212+
return c.Annotations != nil && c.Annotations["trace"] == "true" //nolint
209213
}
210214

211215
func (c Canary) IsDebug() bool {

0 commit comments

Comments
 (0)