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

Add support for tailing Kubernetes pod logs #392

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ type ServerConfig struct {
AivenProjectID string `ini:"aiven_project_id"`
AivenServiceID string `ini:"aiven_service_id"`

K8sKubeConfigPath string `ini:"k8s_kubeconfig_path"`
K8sApiServerUrl string `ini:"k8s_api_server_url"`

SectionName string
Identifier ServerIdentifier

Expand All @@ -133,6 +136,13 @@ type ServerConfig struct {
// on the specifed "hostname:port" for Postgres log messages
LogSyslogServer string `ini:"db_log_syslog_server"`

// Configure the collector to tail a container within a Kubernetes pod
LogKubernetesPod string `ini:"db_log_kubernetes_pod"`
// The container name within the kubernetes pod to tail
LogKubernetesContainer string `ini:"db_log_kubernetes_container"`
// The namespace of the pod to tail, if not set will be "default"
LogKubernetesNamespace string `ini:"db_log_kubernetes_namespace"`

// Configures the collector to use the "pg_read_file" (superuser) or
// "pganalyze.read_log_file" (helper) function to retrieve log data
// directly over the Postgres connection. This only works when superuser
Expand Down
6 changes: 6 additions & 0 deletions config/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ func getDefaultConfig() *ServerConfig {
if logSyslogServer := os.Getenv("LOG_SYSLOG_SERVER"); logSyslogServer != "" {
config.LogSyslogServer = logSyslogServer
}
if logKubernetesPodName := os.Getenv("LOG_KUBERNETES_POD"); logKubernetesPodName != "" {
config.LogKubernetesPod = logKubernetesPodName
}
if logKubernetesContainerName := os.Getenv("LOG_KUBERNETES_CONTAINER"); logKubernetesContainerName != "" {
config.LogKubernetesContainer = logKubernetesContainerName
}
if alwaysCollectSystemData := os.Getenv("PGA_ALWAYS_COLLECT_SYSTEM_DATA"); alwaysCollectSystemData != "" {
config.AlwaysCollectSystemData = parseConfigBool(alwaysCollectSystemData)
}
Expand Down
45 changes: 37 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/go-ini/ini v1.62.0
github.com/go-ole/go-ole v0.0.0-20160708033836-be49f7c07711 // indirect
github.com/golang-jwt/jwt/v4 v4.1.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorhill/cronexpr v0.0.0-20160318121724-f0984319b442
github.com/guregu/null v0.0.0-20160228005316-41961cea0328
Expand All @@ -30,7 +30,6 @@ require (
github.com/jtolds/gls v4.2.0+incompatible // indirect
github.com/juju/syslog v0.0.0-20150205155936-6be94e8b7187
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
github.com/kr/pretty v0.2.1 // indirect
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758
github.com/lib/pq v1.10.7
github.com/mitchellh/mapstructure v1.4.2 // indirect
Expand All @@ -44,14 +43,16 @@ require (
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.7.0
google.golang.org/api v0.32.0
google.golang.org/protobuf v1.25.0
google.golang.org/protobuf v1.28.1
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/mcuadros/go-syslog.v2 v2.3.0
)

require (
github.com/pganalyze/pg_query_go/v4 v4.2.0
github.com/prometheus/procfs v0.7.3
k8s.io/api v0.26.2
k8s.io/client-go v0.26.2
)

require (
Expand All @@ -62,31 +63,59 @@ require (
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/devigned/tab v0.1.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/google/go-cmp v0.5.4 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
go.opencensus.io v0.22.4 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20201002142447-3860012362da // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154 // indirect
google.golang.org/grpc v1.32.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apimachinery v0.26.2 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

go 1.19
Loading