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

feat: implement monitoring bootstrap #190

Merged
merged 12 commits into from
Oct 9, 2024
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
$(KUSTOMIZE) build config/crd | kubectl apply -f - --server-side

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand All @@ -190,7 +190,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE_REPO}/greptimedb-operator:${IMAGE_TAG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
$(KUSTOMIZE) build config/default | kubectl apply -f - --server-side

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand Down
21 changes: 21 additions & 0 deletions apis/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,13 @@ func (in *S3Storage) GetSecretName() string {
return ""
}

func (in *S3Storage) GetRoot() string {
if in != nil {
return in.Root
}
return ""
}

// OSSStorage defines the Aliyun OSS storage specification.
type OSSStorage struct {
// The data will be stored in the bucket.
Expand Down Expand Up @@ -682,6 +689,13 @@ func (in *OSSStorage) GetSecretName() string {
return ""
}

func (in *OSSStorage) GetRoot() string {
if in != nil {
return in.Root
}
return ""
}

// GCSStorage defines the Google GCS storage specification.
type GCSStorage struct {
// The data will be stored in the bucket.
Expand Down Expand Up @@ -714,6 +728,13 @@ func (in *GCSStorage) GetSecretName() string {
return ""
}

func (in *GCSStorage) GetRoot() string {
if in != nil {
return in.Root
}
return ""
}

// PrometheusMonitorSpec defines the PodMonitor configuration.
type PrometheusMonitorSpec struct {
// Enabled indicates whether the PodMonitor is enabled.
Expand Down
16 changes: 14 additions & 2 deletions apis/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const (
// DefaultVersion is the default version of the GreptimeDB.
DefaultVersion = "Unknown"

// DefautlHealthEndpoint is the default health endpoint for the liveness probe.
DefautlHealthEndpoint = "/health"
// DefaultHealthEndpoint is the default health endpoint for the liveness probe.
DefaultHealthEndpoint = "/health"

// DefaultHTTPPort is the default HTTP port for the GreptimeDB.
DefaultHTTPPort int32 = 4000
Expand Down Expand Up @@ -58,8 +58,20 @@ const (
// DefaultInitializerImage is the default image for the GreptimeDB initializer.
DefaultInitializerImage = "greptime/greptimedb-initializer:latest"

// DefaultGreptimeDBImage is the default image for the GreptimeDB.
DefaultGreptimeDBImage = "greptime/greptimedb:latest"
zyy17 marked this conversation as resolved.
Show resolved Hide resolved

// DefaultLoggingLevel is the default logging level for the GreptimeDB.
DefaultLoggingLevel = LoggingLevelInfo

// DefaultVectorImage is the default image for the vector.
DefaultVectorImage = "timberio/vector:nightly-alpine"

// DefaultVectorCPURequest is the default CPU request for the vector.
DefaultVectorCPURequest = "50m"

// DefaultVectorMemoryRequest is the default memory request for the vector.
DefaultVectorMemoryRequest = "128Mi"
)

// The following constants are the constant configuration for the GreptimeDBCluster and GreptimeDBStandalone.
Expand Down
113 changes: 111 additions & 2 deletions apis/v1alpha1/defaulting.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
package v1alpha1

import (
"fmt"
"strings"

"dario.cat/mergo"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
)
Expand All @@ -43,6 +45,11 @@ func (in *GreptimeDBCluster) SetDefaults() error {
return err
}

// Merge the logging settings into the GreptimeDBClusterSpec.
if err := in.mergeLogging(); err != nil {
return err
}

return nil
}

Expand All @@ -54,7 +61,7 @@ func (in *GreptimeDBCluster) defaultSpec() *GreptimeDBClusterSpec {
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: DefautlHealthEndpoint,
Path: DefaultHealthEndpoint,
Port: intstr.FromInt32(DefaultHTTPPort),
},
},
Expand All @@ -78,6 +85,29 @@ func (in *GreptimeDBCluster) defaultSpec() *GreptimeDBClusterSpec {

defaultSpec.Logging = defaultLogging()

if in.GetMonitoring().IsEnabled() {
defaultSpec.Monitoring = &MonitoringSpec{
Standalone: in.defaultMonitoringStandaloneSpec(),
LogsCollection: &LogsCollectionSpec{},
Vector: &VectorSpec{
Image: DefaultVectorImage,
Resource: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(DefaultVectorCPURequest),
corev1.ResourceMemory: resource.MustParse(DefaultVectorMemoryRequest),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(DefaultVectorCPURequest),
corev1.ResourceMemory: resource.MustParse(DefaultVectorMemoryRequest),
},
},
},
}

// Set the default logging format to JSON if monitoring is enabled.
defaultSpec.Logging.Format = LogFormatJSON
}

return defaultSpec
}

Expand All @@ -86,6 +116,7 @@ func (in *GreptimeDBCluster) defaultFrontend() *FrontendSpec {
ComponentSpec: ComponentSpec{
Template: &PodTemplateSpec{},
Replicas: pointer.Int32(DefaultReplicas),
Logging: &LoggingSpec{},
},
RPCPort: DefaultRPCPort,
HTTPPort: DefaultHTTPPort,
Expand All @@ -106,6 +137,7 @@ func (in *GreptimeDBCluster) defaultMeta() *MetaSpec {
ComponentSpec: ComponentSpec{
Template: &PodTemplateSpec{},
Replicas: pointer.Int32(DefaultReplicas),
Logging: &LoggingSpec{},
},
RPCPort: DefaultMetaRPCPort,
HTTPPort: DefaultHTTPPort,
Expand All @@ -118,6 +150,7 @@ func (in *GreptimeDBCluster) defaultDatanode() *DatanodeSpec {
ComponentSpec: ComponentSpec{
Template: &PodTemplateSpec{},
Replicas: pointer.Int32(DefaultReplicas),
Logging: &LoggingSpec{},
},
RPCPort: DefaultRPCPort,
HTTPPort: DefaultHTTPPort,
Expand All @@ -130,11 +163,43 @@ func (in *GreptimeDBCluster) defaultFlownodeSpec() *FlownodeSpec {
ComponentSpec: ComponentSpec{
Template: &PodTemplateSpec{},
Replicas: pointer.Int32(DefaultReplicas),
Logging: &LoggingSpec{},
},
RPCPort: DefaultRPCPort,
}
}

func (in *GreptimeDBCluster) defaultMonitoringStandaloneSpec() *GreptimeDBStandaloneSpec {
standalone := new(GreptimeDBStandalone)
standalone.Spec = *standalone.defaultSpec()

if image := in.GetBaseMainContainer().GetImage(); image != "" {
standalone.Spec.Base.MainContainer.Image = image
} else {
standalone.Spec.Base.MainContainer.Image = DefaultGreptimeDBImage
}

standalone.Spec.Version = getVersionFromImage(standalone.Spec.Base.MainContainer.Image)

if osp := in.GetObjectStorageProvider(); osp != nil {
standalone.Spec.ObjectStorageProvider = osp.DeepCopy()

if root := osp.GetS3Storage().GetRoot(); root != "" {
standalone.Spec.ObjectStorageProvider.S3.Root = fmt.Sprintf("%s/monitoring", root)
zyy17 marked this conversation as resolved.
Show resolved Hide resolved
}

if root := osp.GetOSSStorage().GetRoot(); root != "" {
standalone.Spec.ObjectStorageProvider.OSS.Root = fmt.Sprintf("%s/monitoring", root)
}

if root := osp.GetGCSStorage().GetRoot(); root != "" {
standalone.Spec.ObjectStorageProvider.GCS.Root = fmt.Sprintf("%s/monitoring", root)
}
}

return &standalone.Spec
}

func (in *GreptimeDBCluster) mergeTemplate() error {
if err := in.mergeFrontendTemplate(); err != nil {
return err
Expand Down Expand Up @@ -211,6 +276,50 @@ func (in *GreptimeDBCluster) mergeFlownodeTemplate() error {
return nil
}

func (in *GreptimeDBCluster) mergeLogging() error {
if logging := in.GetMeta().GetLogging(); logging != nil {
if err := mergo.Merge(logging, in.GetLogging().DeepCopy()); err != nil {
return err
}
if in.GetMonitoring().IsEnabled() {
// Set the default logging format to JSON if monitoring is enabled.
logging.Format = LogFormatJSON
}
}

if logging := in.GetDatanode().GetLogging(); logging != nil {
if err := mergo.Merge(logging, in.GetLogging().DeepCopy()); err != nil {
return err
}
if in.GetMonitoring().IsEnabled() {
// Set the default logging format to JSON if monitoring is enabled.
logging.Format = LogFormatJSON
zyy17 marked this conversation as resolved.
Show resolved Hide resolved
}
}

if logging := in.GetFrontend().GetLogging(); logging != nil {
if err := mergo.Merge(logging, in.GetLogging().DeepCopy()); err != nil {
return err
}
if in.GetMonitoring().IsEnabled() {
// Set the default logging format to JSON if monitoring is enabled.
logging.Format = LogFormatJSON
}
}

if logging := in.GetFlownode().GetLogging(); logging != nil {
if err := mergo.Merge(logging, in.GetLogging().DeepCopy()); err != nil {
return err
}
if in.GetMonitoring().IsEnabled() {
// Set the default logging format to JSON if monitoring is enabled.
logging.Format = LogFormatJSON
}
}

return nil
zyy17 marked this conversation as resolved.
Show resolved Hide resolved
}

func (in *GreptimeDBStandalone) SetDefaults() error {
if in == nil {
return nil
Expand All @@ -235,7 +344,7 @@ func (in *GreptimeDBStandalone) defaultSpec() *GreptimeDBStandaloneSpec {
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: DefautlHealthEndpoint,
Path: DefaultHealthEndpoint,
Port: intstr.FromInt32(DefaultHTTPPort),
},
},
Expand Down
Loading
Loading