Skip to content

Commit

Permalink
Add metrics for components
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Nov 24, 2023
1 parent 61395d3 commit 395e97e
Show file tree
Hide file tree
Showing 26 changed files with 645 additions and 460 deletions.
25 changes: 25 additions & 0 deletions pkg/apis/config/v1alpha1/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ type Component struct {
// +optional
Volumes []Volume `json:"volumes,omitempty"`

// Metric is the metric of the component.
Metric *ComponentMetric `json:"metric,omitempty"`

// MetricsDiscoveries is the metrics discovery of the component.
MetricsDiscoveries []ComponentMetric `json:"metricsDiscoveries,omitempty"`

// Version is the version of the component.
// +optional
Version string `json:"version,omitempty"`
Expand Down Expand Up @@ -494,6 +500,25 @@ type Port struct {
Protocol Protocol `json:"protocol,omitempty"`
}

// ComponentMetric represents a metric of a component.
type ComponentMetric struct {
// Name is the name of the metrics discovery.
Name string `json:"name,omitempty"`
// Scheme is the scheme of the metric.
Scheme string `json:"scheme"`
// Host is the host of the metric.
Host string `json:"host"`
// Path is the path of the metric.
Path string `json:"path"`

// CertPath is the cert path of the metric.
CertPath string `json:"certPath,omitempty"`
// KeyPath is the key path of the metric.
KeyPath string `json:"keyPath,omitempty"`
// InsecureSkipVerify is the flag to skip verify the metric.
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
}

// Protocol defines network protocols supported for things like component ports.
// +enum
type Protocol string
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions pkg/apis/internalversion/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ type Component struct {
// Volumes is a list of named volumes that can be mounted by containers belonging to the component.
Volumes []Volume

// Metric is the metric of the component.
Metric *ComponentMetric

// MetricsDiscoveries is the metrics discovery of the component.
MetricsDiscoveries []ComponentMetric

// Version is the version of the component.
Version string
}
Expand Down Expand Up @@ -331,6 +337,25 @@ type Port struct {
Protocol Protocol
}

// ComponentMetric represents a metric of a component.
type ComponentMetric struct {
// Name is the name of the metrics discovery.
Name string
// Scheme is the scheme of the metric.
Scheme string
// Host is the host of the metric.
Host string
// Path is the path of the metric.
Path string

// CertPath is the cert path of the metric.
CertPath string
// KeyPath is the key path of the metric.
KeyPath string
// InsecureSkipVerify is the flag to skip verify the metric.
InsecureSkipVerify bool
}

// Protocol defines network protocols supported for things like component ports.
type Protocol string

Expand Down
46 changes: 46 additions & 0 deletions pkg/apis/internalversion/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions pkg/apis/internalversion/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/kwokctl/components/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import (
"sigs.k8s.io/kwok/pkg/log"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/version"

Check failure on line 26 in pkg/kwokctl/components/etcd.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(sigs.k8s.io/kwok) -s blank -s dot --custom-order (gci)
"sigs.k8s.io/kwok/pkg/utils/net"

Check failure on line 27 in pkg/kwokctl/components/etcd.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(sigs.k8s.io/kwok) -s blank -s dot --custom-order (gci)
)

// BuildEtcdComponentConfig is the configuration for building an etcd component.
type BuildEtcdComponentConfig struct {
Binary string
Image string
ProjectName string
Version version.Version
DataPath string
Workdir string
Expand Down Expand Up @@ -67,6 +69,7 @@ func BuildEtcdComponent(conf BuildEtcdComponentConfig) (component internalversio
etcdArgs = append(etcdArgs, extraArgsToStrings(conf.ExtraArgs)...)

inContainer := conf.Image != ""
var metric *internalversion.ComponentMetric
if inContainer {
// TODO: use a volume for the data path
// volumes = append(volumes,
Expand Down Expand Up @@ -104,6 +107,12 @@ func BuildEtcdComponent(conf BuildEtcdComponentConfig) (component internalversio
"--listen-client-urls=http://"+conf.BindAddress+":2379",
"--initial-cluster=node0=http://"+conf.BindAddress+":2380",
)

metric = &internalversion.ComponentMetric{
Scheme: "http",
Host: conf.ProjectName + "-" + consts.ComponentEtcd + ":2379",
Path: "/metrics",
}
} else {
etcdPeerPortStr := format.String(conf.PeerPort)
etcdClientPortStr := format.String(conf.Port)
Expand All @@ -115,6 +124,12 @@ func BuildEtcdComponent(conf BuildEtcdComponentConfig) (component internalversio
"--listen-client-urls=http://"+conf.BindAddress+":"+etcdClientPortStr,
"--initial-cluster=node0=http://"+conf.BindAddress+":"+etcdPeerPortStr,
)

metric = &internalversion.ComponentMetric{
Scheme: "http",
Host: net.LocalAddress + ":" + etcdClientPortStr,
Path: "/metrics",
}
}

if conf.Version.GTE(version.NewVersion(3, 4, 0)) {
Expand Down Expand Up @@ -144,6 +159,7 @@ func BuildEtcdComponent(conf BuildEtcdComponentConfig) (component internalversio
Args: etcdArgs,
Binary: conf.Binary,
Ports: ports,
Metric: metric,
Image: conf.Image,
WorkDir: conf.Workdir,
Envs: envs,
Expand Down
31 changes: 30 additions & 1 deletion pkg/kwokctl/components/kube_apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import (
"sigs.k8s.io/kwok/pkg/log"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/version"

Check failure on line 27 in pkg/kwokctl/components/kube_apiserver.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(sigs.k8s.io/kwok) -s blank -s dot --custom-order (gci)
"sigs.k8s.io/kwok/pkg/utils/net"

Check failure on line 28 in pkg/kwokctl/components/kube_apiserver.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(sigs.k8s.io/kwok) -s blank -s dot --custom-order (gci)
)

// BuildKubeApiserverComponentConfig is the configuration for building a kube-apiserver component.
type BuildKubeApiserverComponentConfig struct {
ProjectName string
Binary string
Image string
Version version.Version
Expand Down Expand Up @@ -120,7 +122,7 @@ func BuildKubeApiserverComponent(conf BuildKubeApiserverComponentConfig) (compon
var ports []internalversion.Port
var volumes []internalversion.Volume
volumes = append(volumes, conf.ExtraVolumes...)

var metric *internalversion.ComponentMetric
inContainer := conf.Image != ""
if inContainer {
kubeApiserverArgs = append(kubeApiserverArgs,
Expand Down Expand Up @@ -173,6 +175,14 @@ func BuildKubeApiserverComponent(conf BuildKubeApiserverComponentConfig) (compon
"--service-account-signing-key-file=/etc/kubernetes/pki/admin.key",
"--service-account-issuer=https://kubernetes.default.svc.cluster.local",
)
metric = &internalversion.ComponentMetric{
Scheme: "https",
Host: conf.ProjectName + "-" + consts.ComponentKubeApiserver + ":6443",
Path: "/metrics",
CertPath: "/etc/kubernetes/pki/admin.crt",
KeyPath: "/etc/kubernetes/pki/admin.key",
InsecureSkipVerify: true,
}
} else {
kubeApiserverArgs = append(kubeApiserverArgs,
"--bind-address="+conf.BindAddress,
Expand All @@ -184,6 +194,14 @@ func BuildKubeApiserverComponent(conf BuildKubeApiserverComponentConfig) (compon
"--service-account-signing-key-file="+conf.AdminKeyPath,
"--service-account-issuer=https://kubernetes.default.svc.cluster.local",
)
metric = &internalversion.ComponentMetric{
Scheme: "https",
Host: net.LocalAddress + ":" + format.String(conf.Port),
Path: "/metrics",
CertPath: conf.AdminCertPath,
KeyPath: conf.AdminKeyPath,
InsecureSkipVerify: true,
}
}
} else {
if inContainer {
Expand All @@ -198,11 +216,21 @@ func BuildKubeApiserverComponent(conf BuildKubeApiserverComponentConfig) (compon
"--insecure-bind-address="+conf.BindAddress,
"--insecure-port=8080",
)
metric = &internalversion.ComponentMetric{
Scheme: "http",
Host: conf.ProjectName + "-" + consts.ComponentKubeApiserver + ":8080",
Path: "/metrics",
}
} else {
kubeApiserverArgs = append(kubeApiserverArgs,
"--insecure-bind-address="+conf.BindAddress,
"--insecure-port="+format.String(conf.Port),
)
metric = &internalversion.ComponentMetric{
Scheme: "http",
Host: net.LocalAddress + ":" + format.String(conf.Port),
Path: "/metrics",
}
}
}

Expand Down Expand Up @@ -273,6 +301,7 @@ func BuildKubeApiserverComponent(conf BuildKubeApiserverComponentConfig) (compon
Args: kubeApiserverArgs,
Binary: conf.Binary,
Image: conf.Image,
Metric: metric,
WorkDir: conf.Workdir,
Envs: envs,
}, nil
Expand Down
Loading

0 comments on commit 395e97e

Please sign in to comment.