Skip to content
Merged
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
44 changes: 39 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ main ]

env:
GO_VERSION: '1.24.4'
GO_VERSION: '1.26'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

Expand Down Expand Up @@ -58,10 +58,44 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
with:
version: latest
args: --timeout=5m
version: v2.11.4 # pin explicit version

vuln:
name: Vulnerability Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@v1.1.4

- name: Run govulncheck
run: govulncheck ./...

tidy:
name: Module Tidy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Check go mod tidy
run: |
go mod tidy
git diff --exit-code go.mod go.sum

docker-build:
name: Docker Build Test
Expand All @@ -80,7 +114,7 @@ jobs:
context: .
file: ./Dockerfile
push: false
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
tags: ${{ env.REGISTRY }}/fraser-isbester/cloudsql-autoscaler:test
cache-from: type=gha
cache-to: type=gha,mode=max

Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Pages

on:
push:
branches: [main]
paths:
- "site/**"
- ".github/workflows/pages.yml"
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment; don't cancel an in-progress run.
concurrency:
group: pages
cancel-in-progress: false

jobs:
build:
name: Build site
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0

- uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
with:
path: site

deploy:
name: Deploy to GitHub Pages
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

env:
GO_VERSION: '1.24.4'
GO_VERSION: '1.26'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

Expand Down
107 changes: 23 additions & 84 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,96 +1,35 @@
run:
timeout: 5m
go: "1.24.4"

linters-settings:
gofmt:
simplify: true
goimports:
local-prefixes: github.com/fraser-isbester/cloudsql-autoscaler
govet:
check-shadowing: true
errcheck:
check-type-assertions: true
check-blank: true
golint:
min-confidence: 0.8
misspell:
locale: US
gocyclo:
min-complexity: 15
goconst:
min-len: 3
min-occurrences: 3
funlen:
lines: 100
statements: 50
godox:
keywords:
- NOTE
- OPTIMIZE
- HACK
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
version: "2"

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- exportloopref
- exhaustive
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- staticcheck
- unused
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- gosec
- unconvert
- unparam
- unused
- varcheck
- whitespace
- prealloc
settings:
misspell:
locale: US
exclusions:
rules:
- path: _test\.go
linters:
- gosec

formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/fraser-isbester/cloudsql-autoscaler

issues:
exclude-rules:
- path: _test\.go
linters:
- gomnd
- funlen
- path: cmd/
linters:
- gochecknoinits
max-issues-per-linter: 0
max-same-issues: 0
max-same-issues: 0
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Multi-stage Dockerfile for cloudsql-autoscaler
# Stage 1: Build environment
FROM golang:1.24.4-alpine AS builder
FROM golang:1.26.5-alpine AS builder

# Set working directory
WORKDIR /app
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build clean test fmt vet install help docker-build docker-push docker-run deploy-k8s undeploy-k8s
.PHONY: build clean test fmt vet vuln install help docker-build docker-push docker-run deploy-k8s undeploy-k8s
.DEFAULT_GOAL := help

# Build variables
Expand Down Expand Up @@ -44,8 +44,12 @@ fmt:
vet:
go vet ./...

## Run all checks (fmt, vet, build, test)
check: fmt vet build test
## Run govulncheck
vuln:
go run golang.org/x/vuln/cmd/govulncheck@v1.1.4 ./...

## Run all checks (fmt, vet, vuln, build, test)
check: fmt vet vuln build test

## Clean build artifacts
clean:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CloudSQL Autoscaler

**Website:** https://fraser-isbester.github.io/cloudsql-autoscaler/

Automatically scales Google Cloud SQL instances based on CPU and memory utilization patterns. Supports both one-shot CLI usage and continuous daemon mode for production deployments.

## Features
Expand Down
8 changes: 4 additions & 4 deletions cmd/cloudsql-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ func runAutoscaler(cmd *cobra.Command, args []string) error {

// Handle daemon mode
if daemonMode {
return runDaemon(ctx, cfg)
return runDaemon(cfg)
}

// Handle one-shot mode
projectAnalyzer, err := analyzer.NewProjectAnalyzer(ctx, cfg)
if err != nil {
return fmt.Errorf("failed to create analyzer: %w", err)
}
defer projectAnalyzer.Close()
defer func() { _ = projectAnalyzer.Close() }()

if output != "table" && output != "json" {
return fmt.Errorf("invalid output format: %s (must be 'table' or 'json')", output)
Expand All @@ -182,7 +182,7 @@ func runAutoscaler(cmd *cobra.Command, args []string) error {
return analyzeAllInstances(ctx, projectAnalyzer)
}

func runDaemon(ctx context.Context, cfg *config.Config) error {
func runDaemon(cfg *config.Config) error {
// Initialize metrics if enabled
if enableMetrics {
daemon.InitMetrics()
Expand Down Expand Up @@ -416,7 +416,7 @@ func countErrors(results []OutputResult) int {

func getDefaultProjectID(ctx context.Context) (string, error) {
if metadata.OnGCE() {
project, err := metadata.ProjectID()
project, err := metadata.ProjectIDWithContext(ctx)
if err == nil {
return project, nil
}
Expand Down
45 changes: 28 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
module github.com/fraser-isbester/cloudsql-autoscaler

go 1.24.4
go 1.26.5

require (
cloud.google.com/go/compute/metadata v0.7.0
cloud.google.com/go/compute/metadata v0.9.0
cloud.google.com/go/monitoring v1.24.2
github.com/onsi/ginkgo/v2 v2.32.0
github.com/onsi/gomega v1.42.1
github.com/prometheus/client_golang v1.20.5
github.com/spf13/cobra v1.9.1
google.golang.org/api v0.241.0
google.golang.org/protobuf v1.36.6
google.golang.org/protobuf v1.36.11
)

require (
cloud.google.com/go/auth v0.16.2 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect
github.com/google/s2a-go v0.1.9 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
Expand All @@ -30,21 +36,26 @@ require (
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
go.opentelemetry.io/otel v1.36.0 // indirect
go.opentelemetry.io/otel/metric v1.36.0 // indirect
go.opentelemetry.io/otel/trace v1.36.0 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/net v0.41.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.15.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.26.0 // indirect
go.opentelemetry.io/otel v1.44.0 // indirect
go.opentelemetry.io/otel/metric v1.44.0 // indirect
go.opentelemetry.io/otel/sdk v1.44.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.44.0 // indirect
go.opentelemetry.io/otel/trace v1.44.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.53.0 // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/net v0.56.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sync v0.21.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.38.0 // indirect
golang.org/x/time v0.12.0 // indirect
golang.org/x/tools v0.45.0 // indirect
google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
google.golang.org/grpc v1.73.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260414002931-afd174a4e478 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect
google.golang.org/grpc v1.82.0 // indirect
)
Loading
Loading