Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Temporal metrics collector #25

Merged
merged 5 commits into from
Apr 10, 2024
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
18 changes: 16 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Run tests
run: go test -v ./...

integration:
name: "Integration Tests"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Run unit tests
run: go test -v . ./...
- name: Install Temporal CLI
uses: temporalio/setup-temporal@v0

- name: Run temporal integration tests
run: go test -v -tags integration ./temporal

staticcheck:
name: "Staticcheck"
Expand Down
57 changes: 54 additions & 3 deletions cmd/fly-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

fas "github.com/superfly/fly-autoscaler"
fasprom "github.com/superfly/fly-autoscaler/prometheus"
"github.com/superfly/fly-autoscaler/temporal"
"github.com/superfly/fly-go/flaps"
"github.com/superfly/fly-go/tokens"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -159,6 +160,28 @@ func NewConfigFromEnv() (*Config, error) {
})
}

if addr := os.Getenv("FAS_TEMPORAL_ADDRESS"); addr != "" {
certData := os.Getenv("TEMPORAL_TLS_CERT_DATA")
if certData == "" {
certData = os.Getenv("FAS_TEMPORAL_CERT_DATA")
}

keyData := os.Getenv("TEMPORAL_TLS_KEY_DATA")
if keyData == "" {
keyData = os.Getenv("FAS_TEMPORAL_KEY_DATA")
}

c.MetricCollectors = append(c.MetricCollectors, &MetricCollectorConfig{
Type: "temporal",
Address: addr,
Namespace: os.Getenv("FAS_TEMPORAL_NAMESPACE"),
MetricName: os.Getenv("FAS_TEMPORAL_METRIC_NAME"),
CertData: certData,
KeyData: keyData,
Query: os.Getenv("FAS_TEMPORAL_QUERY"),
})
}

return c, nil
}

Expand Down Expand Up @@ -303,11 +326,16 @@ func ParseConfigFromFile(filename string, config *Config) error {
type MetricCollectorConfig struct {
Type string `yaml:"type"`
MetricName string `yaml:"metric-name"`
Query string `yaml:"query"` // Prometheus & Temporal
Address string `yaml:"address"` // Prometheus & Temporal

// Prometheus fields
Address string `yaml:"address"`
Query string `yaml:"query"`
Token string `yaml:"token"`
Token string `yaml:"token"`

// Temporal fields
Namespace string `yaml:"namespace"`
CertData string `yaml:"cert-data"`
KeyData string `yaml:"key-data"`
}

func (c *MetricCollectorConfig) Validate() error {
Expand All @@ -318,6 +346,8 @@ func (c *MetricCollectorConfig) Validate() error {
switch typ := c.Type; typ {
case "prometheus":
return c.validatePrometheus()
case "temporal":
return c.validateTemporal()
case "":
return fmt.Errorf("type required")
default:
Expand All @@ -335,10 +365,16 @@ func (c *MetricCollectorConfig) validatePrometheus() error {
return nil
}

func (c *MetricCollectorConfig) validateTemporal() error {
return nil
}

func (c *MetricCollectorConfig) NewMetricCollector() (fas.MetricCollector, error) {
switch typ := c.Type; typ {
case "prometheus":
return c.newPrometheusMetricCollector()
case "temporal":
return c.newTemporalMetricCollector()
default:
return nil, fmt.Errorf("invalid type: %q", typ)
}
Expand All @@ -352,3 +388,18 @@ func (c *MetricCollectorConfig) newPrometheusMetricCollector() (*fasprom.MetricC
c.Token,
)
}

func (c *MetricCollectorConfig) newTemporalMetricCollector() (*temporal.MetricCollector, error) {
collector := temporal.NewMetricCollector(c.MetricName)

collector.Address = c.Address
collector.Namespace = c.Namespace
collector.Cert = []byte(c.CertData)
collector.Key = []byte(c.KeyData)
collector.Query = c.Query

if err := collector.Open(); err != nil {
return nil, err
}
return collector, nil
}
7 changes: 7 additions & 0 deletions etc/fly-autoscaler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ metric-collectors:
address: "https://api.fly.io/prometheus/MY_ORG"
query: "sum(queue_depth)"
token: "FlyV1 ..."

- type: "temporal"
metric-name: "workflow_count"
address: "localhost:7233"
cert-data: "-----BEGIN CERTIFICATE-----..."
key-data: "-----BEGIN EC PRIVATE KEY-----..."
query: 'WorkflowType="my_workflow_type"'
32 changes: 26 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ require (
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/common v0.45.0
github.com/superfly/fly-go v0.0.0-20240216161738-ca39fa12b183
go.temporal.io/api v1.30.1
go.temporal.io/sdk v1.26.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -16,22 +19,34 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/superfly/graphql v0.2.4 // indirect
github.com/superfly/macaroon v0.2.10 // indirect
github.com/vektah/gqlparser/v2 v2.5.1 // indirect
Expand All @@ -41,9 +56,14 @@ require (
go.opentelemetry.io/otel v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.17.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading
Loading