Skip to content
3 changes: 2 additions & 1 deletion cmd/ktranslate/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -127,7 +128,7 @@ func main() {

// if config specified, merge config
if v := *configFilePath; v != "" {
ktCfg, err := ktranslate.LoadConfig(v)
ktCfg, err := ktranslate.LoadConfig(context.Background(), v)
if err != nil {
panic(err)
}
Expand Down
27 changes: 12 additions & 15 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ktranslate

import (
"os"

"context"
yaml "gopkg.in/yaml.v3"
"io/fs"

snmp_util "github.com/kentik/ktranslate/pkg/inputs/snmp/util"
)

const (
Expand Down Expand Up @@ -566,36 +568,31 @@ func DefaultConfig() *Config {
}

// LoadConfig returns a ktranslate configuration from the specified path
func LoadConfig(configPath string) (*Config, error) {
f, err := os.Open(configPath)
func LoadConfig(ctx context.Context, configPath string) (*Config, error) {
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LoadConfig function signature has changed from LoadConfig(configPath string) to LoadConfig(ctx context.Context, configPath string). This is a breaking API change that will affect any external code that calls this function.

While the change is necessary to support context propagation for Git operations, this should be documented in release notes or migration guide. The PR correctly updates the main caller in cmd/ktranslate/main.go, but any external consumers of this package would need to update their code.

Copilot uses AI. Check for mistakes.
confBytes, err := snmp_util.LoadFile(ctx, configPath)
if err != nil {
return nil, err
}
defer f.Close()

var cfg *Config
if err := yaml.NewDecoder(f).Decode(&cfg); err != nil {
cfg := Config{}
if err := yaml.Unmarshal(confBytes, &cfg); err != nil {
return nil, err
}

if cfg.Format == "netflow" && (cfg.MaxFlowsPerMessage <= 0 || cfg.MaxFlowsPerMessage > MaxNetflowsPerMessage) {
cfg.MaxFlowsPerMessage = MaxNetflowsPerMessage
}

return cfg, nil
return &cfg, nil
}

// SaveConfig saves the ktranslate configuration to the specified path
func (c *Config) SaveConfig() error {
f, err := os.Create(c.Server.CfgPath)
t, err := yaml.Marshal(c)
if err != nil {
return err
}
defer f.Close()

if err := yaml.NewEncoder(f).Encode(c); err != nil {
return err
}

return nil
permissions := fs.FileMode(0644)
return snmp_util.WriteFile(context.Background(), c.Server.CfgPath, t, permissions)
}
36 changes: 17 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/dchest/siphash v1.2.2
github.com/elliotchance/orderedmap v1.4.0
github.com/fsnotify/fsnotify v1.6.0
github.com/go-git/go-git/v5 v5.16.5
github.com/go-git/go-git/v6 v6.0.0-20260216160506-e6a3f881772f
github.com/go-logr/stdr v1.2.2
github.com/go-openapi/runtime v0.26.0
github.com/gogo/protobuf v1.3.2
Expand Down Expand Up @@ -46,7 +46,7 @@ require (
github.com/prometheus/prometheus v0.46.0
github.com/sasha-s/go-hll v0.0.0-20180522065212-c6eb27aee351
github.com/segmentio/kafka-go v0.4.23
github.com/stretchr/testify v1.10.0
github.com/stretchr/testify v1.11.1
github.com/syndtr/goleveldb v1.0.0
github.com/xitongsys/parquet-go v1.6.2
github.com/xitongsys/parquet-go-source v0.0.0-20240122235623-d6294584ab18
Expand All @@ -58,7 +58,7 @@ require (
go.opentelemetry.io/otel/sdk v1.36.0
go.opentelemetry.io/otel/sdk/metric v1.36.0
go.starlark.net v0.0.0-20220926145019-14b050677505
golang.org/x/net v0.47.0
golang.org/x/net v0.50.0
gonum.org/v1/gonum v0.15.1
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de
google.golang.org/grpc v1.63.2
Expand All @@ -72,31 +72,30 @@ require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.5.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/DataDog/zstd v1.5.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.1.6 // indirect
github.com/ProtonMail/go-crypto v1.3.0 // indirect
github.com/apache/arrow/go/arrow v0.0.0-20200730104253-651201b0f516 // indirect
github.com/apache/thrift v0.14.2 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-bits v0.0.0-20180113010104-bd8a69a71dc2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/facebookgo/limitgroup v0.0.0-20150612190941-6abd8d71ec01 // indirect
github.com/facebookgo/muster v0.0.0-20150708232844-fd3d7953fd52 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/go-git/gcfg/v2 v2.0.2 // indirect
github.com/go-git/go-billy/v6 v6.0.0-20260114122816-19306b749ecc // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.4 // indirect
Expand All @@ -115,11 +114,11 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kevinburke/ssh_config v1.5.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/libp2p/go-reuseport v0.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -129,25 +128,24 @@ require (
github.com/mostlygeek/arp v0.0.0-20170424181311-541a2129847a // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/onsi/ginkgo v1.16.2 // indirect
github.com/onsi/gomega v1.34.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/oschwald/maxminddb-golang v1.11.0 // indirect
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pjbgf/sha1cd v0.5.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/sergi/go-diff v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
github.com/tinylib/msgp v1.1.6 // indirect
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
Expand All @@ -157,16 +155,16 @@ require (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel/trace v1.36.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
gopkg.in/alexcesaro/statsd.v2 v2.0.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Loading