Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ name: checkup

steps:
- name: test-mysql
image: golang:1.14
image: golang:1.26.4
pull: always
commands:
- make test-mysql
- make build-mysql

- name: test-postgres
image: golang:1.14
image: golang:1.26.4
pull: always
commands:
- make test-postgres
- make build-postgres

- name: test-sqlite3
image: golang:1.14
image: golang:1.26.4
pull: always
commands:
- make test-sqlite3
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: go

go:
- 1.14
- 1.26.4
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14-alpine as builder
FROM golang:1.26.4-alpine as builder

ENV CGO_ENABLED=0

Expand Down
2 changes: 1 addition & 1 deletion check/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func TestChecker(t *testing.T) {
assert := func(ok bool, format string, args ...interface{}) {
assert := func(ok bool, format string, args ...any) {
if !ok {
t.Errorf(format, args...)
}
Expand Down
5 changes: 3 additions & 2 deletions check/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package http
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"

"net"
"net/http"
"strings"
Expand Down Expand Up @@ -199,7 +200,7 @@ func (c Checker) checkDown(resp *http.Response) error {
if c.MustContain == "" && c.MustNotContain == "" {
return nil
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("reading response body: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions check/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"

"net"
"time"

Expand Down Expand Up @@ -109,7 +110,7 @@ func (c Checker) doChecks() types.Attempts {
var tlsConfig tls.Config
tlsConfig.InsecureSkipVerify = c.TLSSkipVerify
if c.TLSCAFile != "" {
rootPEM, err := ioutil.ReadFile(c.TLSCAFile)
rootPEM, err := os.ReadFile(c.TLSCAFile)
if err != nil || rootPEM == nil {
return nil, errReadingRootCert
}
Expand Down
15 changes: 8 additions & 7 deletions check/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"os"

"net"
"time"

Expand All @@ -18,11 +19,11 @@ const Type = "tls"
// Checker implements a Checker for TLS endpoints.
//
// TODO: Implement more checks on the certificate and TLS configuration.
// - Cipher suites
// - Protocol versions
// - OCSP stapling
// - Multiple SNIs
// - Other things that you might see at SSL Labs or other TLS health checks
// - Cipher suites
// - Protocol versions
// - OCSP stapling
// - Multiple SNIs
// - Other things that you might see at SSL Labs or other TLS health checks
type Checker struct {
// Name is the name of the endpoint.
Name string `json:"endpoint_name"`
Expand Down Expand Up @@ -92,7 +93,7 @@ func (c Checker) Check() (types.Result, error) {
c.tlsConfig.RootCAs = x509.NewCertPool()
}
for _, fname := range c.TrustedRoots {
pemData, err := ioutil.ReadFile(fname)
pemData, err := os.ReadFile(fname)
if err != nil {
return types.Result{}, fmt.Errorf("error loading file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions check/tls/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestChecker(t *testing.T) {

func makeSelfSignedCert(hostname, keyType string, validity time.Duration) (tls.Certificate, error) {
// start by generating private key
var privKey interface{}
var privKey any
var err error
switch keyType {
case "", "ec256":
Expand Down Expand Up @@ -168,7 +168,7 @@ func makeSelfSignedCert(hostname, keyType string, validity time.Duration) (tls.C
}
cert.DNSNames = append(cert.DNSNames, hostname)

publicKey := func(privKey interface{}) interface{} {
publicKey := func(privKey any) any {
switch k := privKey.(type) {
case *rsa.PrivateKey:
return &k.PublicKey
Expand Down
10 changes: 5 additions & 5 deletions checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Checkup struct {
// Useful if wanting to perform distributed check
// "at the same time" even if they might actually
// be a few milliseconds or seconds apart.
Timestamp time.Time `json:"timestamp,omitempty"`
Timestamp time.Time `json:"timestamp"`

// Storage is the storage mechanism for saving the
// results of checks. Required if calling Store().
Expand Down Expand Up @@ -148,7 +148,7 @@ func (c Checkup) MarshalJSON() ([]byte, error) {
// handling; unfortunately this has to mimic c's definition.
easy := struct {
ConcurrentChecks int `json:"concurrent_checks,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
Timestamp time.Time `json:"timestamp"`
}{
ConcurrentChecks: c.ConcurrentChecks,
Timestamp: c.Timestamp,
Expand All @@ -175,7 +175,7 @@ func (c Checkup) MarshalJSON() ([]byte, error) {
if err != nil {
return result, err
}
chb = []byte(fmt.Sprintf(`{"type":"%s",%s`, ch.Type(), string(chb[1:])))
chb = fmt.Appendf(nil, `{"type":"%s",%s`, ch.Type(), string(chb[1:]))
checkers = append(checkers, chb)
}

Expand All @@ -192,7 +192,7 @@ func (c Checkup) MarshalJSON() ([]byte, error) {
if err != nil {
return result, err
}
sb = []byte(fmt.Sprintf(`{"type":"%s",%s`, c.Storage.Type(), string(sb[1:])))
sb = fmt.Appendf(nil, `{"type":"%s",%s`, c.Storage.Type(), string(sb[1:]))
wrap("storage", sb)
}

Expand All @@ -205,7 +205,7 @@ func (c Checkup) MarshalJSON() ([]byte, error) {
return result, err
}

chb = []byte(fmt.Sprintf(`{"type":"%s",%s`, ch.Type(), string(chb[1:])))
chb = fmt.Appendf(nil, `{"type":"%s",%s`, ch.Type(), string(chb[1:]))
checkers = append(checkers, chb)
}

Expand Down
5 changes: 3 additions & 2 deletions checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package checkup
import (
"bytes"
"errors"
"io/ioutil"
"os"

"sync"
"testing"
"time"
Expand Down Expand Up @@ -182,7 +183,7 @@ func TestJSON(t *testing.T) {
testConfig = "testdata/config.json"
)

jsonBytes, err := ioutil.ReadFile(testConfig)
jsonBytes, err := os.ReadFile(testConfig)
if err != nil {
t.Fatalf("Error reading config file: %s", testConfig)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"

"log"
"os"

Expand Down Expand Up @@ -67,7 +67,7 @@ store the results of the check, use --store.`,
}

func loadCheckup() checkup.Checkup {
configBytes, err := ioutil.ReadFile(configFile)
configBytes, err := os.ReadFile(configFile)
if err != nil {
log.Fatal(err)
}
Expand Down
26 changes: 20 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
module github.com/sourcegraph/checkup

go 1.13
go 1.26.4

require (
github.com/ashwanthkumar/slack-go-webhook v0.0.0-20200209025033-430dd4e66960
github.com/aws/aws-sdk-go v1.30.7
github.com/elazarl/goproxy v0.0.0-20200315184450-1f3cb6622dad // indirect
github.com/fatih/color v1.9.0
github.com/go-sql-driver/mysql v1.5.0
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/gregdel/pushover v0.0.0-20200416074932-c8ad547caed4
github.com/jmoiron/sqlx v1.2.0
github.com/lib/pq v1.3.0
github.com/mailgun/mailgun-go/v4 v4.1.0
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/microsoft/ApplicationInsights-Go v0.4.3
github.com/miekg/dns v1.1.29
github.com/spf13/cobra v0.0.7
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
)

require (
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c // indirect
github.com/elazarl/goproxy v0.0.0-20200315184450-1f3cb6622dad // indirect
github.com/go-chi/chi v4.0.0+incompatible // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.3.0 // indirect
github.com/mailru/easyjson v0.7.0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
github.com/parnurzeal/gorequest v0.2.16 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/spf13/cobra v0.0.7
github.com/spf13/pflag v1.0.3 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.28.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
moul.io/http2curl v1.0.0 // indirect
)
5 changes: 3 additions & 2 deletions notifier/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"

"log"
"net/http"
"strings"
Expand Down Expand Up @@ -97,7 +98,7 @@ func (s Notifier) Send(result types.Result) error {
defer resp.Body.Close()

if resp.StatusCode != http.StatusNoContent {
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Println("discord: error reading response body", err)
}
Expand Down
5 changes: 2 additions & 3 deletions storage/appinsights/appinsights.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package appinsights
import (
"encoding/json"
"fmt"
"maps"
"strconv"
"time"

Expand Down Expand Up @@ -92,9 +93,7 @@ func (Storage) Type() string {
func (c Storage) Store(results []types.Result) error {
c.telemetryConfig.InstrumentationKey = c.InstrumentationKey
c.client = appinsights.NewTelemetryClientFromConfig(c.telemetryConfig)
for k, v := range c.Tags {
c.client.Context().CommonProperties[k] = v
}
maps.Copy(c.client.Context().CommonProperties, c.Tags)
for _, result := range results {
c.send(result)
}
Expand Down
19 changes: 10 additions & 9 deletions storage/appinsights/appinsights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"compress/gzip"
"encoding/json"
"fmt"
"io/ioutil"
"io"

"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -124,18 +125,18 @@ func setup(delay time.Duration, retries int, interval int, timeout int, results
req, err := gzip.NewReader(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("gzip NewReader: %v", err)))
w.Write(fmt.Appendf(nil, "gzip NewReader: %v", err))
}
b, _ := ioutil.ReadAll(req)
b, _ := io.ReadAll(req)
parsed, err := parsePayload(b)
for i, j := range parsed {
data := j["data"].(map[string]interface{})
baseData := data["baseData"].(map[string]interface{})
data := j["data"].(map[string]any)
baseData := data["baseData"].(map[string]any)

got, ok := baseData["name"].(string)
if !ok || got != results[i].Title {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("Expected test result name to be '%s', but got '%s'", results[i].Title, got)))
w.Write(fmt.Appendf(nil, "Expected test result name to be '%s', but got '%s'", results[i].Title, got))
}
}
}))
Expand All @@ -161,14 +162,14 @@ func setup(delay time.Duration, retries int, interval int, timeout int, results
}

// Ref: https://github.com/microsoft/ApplicationInsights-Go/blob/master/appinsights/jsonserializer_test.go
func parsePayload(payload []byte) (result []map[string]interface{}, err error) {
for _, item := range bytes.Split(payload, []byte("\n")) {
func parsePayload(payload []byte) (result []map[string]any, err error) {
for item := range bytes.SplitSeq(payload, []byte("\n")) {
if len(item) == 0 {
continue
}

decoder := json.NewDecoder(bytes.NewReader(item))
msg := make(map[string]interface{})
msg := make(map[string]any)
if err := decoder.Decode(&msg); err == nil {
result = append(result, msg)
} else {
Expand Down
5 changes: 2 additions & 3 deletions storage/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fs

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -15,7 +14,7 @@ func TestStorage(t *testing.T) {
results := []types.Result{{Title: "Testing"}}
resultsBytes := []byte(`[{"title":"Testing"}]` + "\n")

dir, err := ioutil.TempDir("", "checkup")
dir, err := os.MkdirTemp("", "checkup")
if err != nil {
t.Fatalf("Cannot create temporary directory: %v", err)
}
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestStorage(t *testing.T) {

// Make sure check file bytes are correct
checkfile := filepath.Join(specimen.Dir, name)
b, err := ioutil.ReadFile(checkfile)
b, err := os.ReadFile(checkfile)
if err != nil {
t.Fatalf("Expected no error reading body, got: %v", err)
}
Expand Down
Loading