Skip to content

Commit

Permalink
Add Monitoring support for Solr (#1151)
Browse files Browse the repository at this point in the history
Signed-off-by: pritamdas99 <pritam@appscode.com>
  • Loading branch information
pritamdas99 authored Mar 16, 2024
1 parent 4a4c398 commit ed0e97c
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 9 deletions.
11 changes: 11 additions & 0 deletions apis/kubedb/v1alpha2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,17 @@ var (
},
}

// DefaultResourcesCoreAndMemoryIntensive must be used for Solr
DefaultResourcesCoreAndMemoryIntensiveSolr = core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(".900"),
core.ResourceMemory: resource.MustParse("2Gi"),
},
Limits: core.ResourceList{
core.ResourceMemory: resource.MustParse("2Gi"),
},
}

// DefaultResourcesMemoryIntensiveSDB must be used for Singlestore when enabled monitoring or version >= 8.5.x
DefaultResourcesMemoryIntensiveSDB = core.ResourceRequirements{
Requests: core.ResourceList{
Expand Down
29 changes: 28 additions & 1 deletion apis/kubedb/v1alpha2/openapi_generated.go

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

57 changes: 49 additions & 8 deletions apis/kubedb/v1alpha2/solr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"kubedb.dev/apimachinery/apis/kubedb"
"kubedb.dev/apimachinery/crds"

promapi "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"gomodules.xyz/pointer"
v1 "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -34,6 +35,7 @@ import (
meta_util "kmodules.xyz/client-go/meta"
"kmodules.xyz/client-go/policy/secomp"
appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
mona "kmodules.xyz/monitoring-agent-api/api/v1"
ofst "kmodules.xyz/offshoot-api/api/v2"
pslister "kubeops.dev/petset/client/listers/apps/v1"
)
Expand Down Expand Up @@ -179,6 +181,51 @@ func (s *Solr) GetConnectionScheme() string {
return scheme
}

func (s *Solr) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string {
svcTemplate := GetServiceTemplate(s.Spec.ServiceTemplates, alias)
return s.offshootLabels(meta_util.OverwriteKeys(s.OffshootSelectors(), extraLabels...), svcTemplate.Labels)
}

type solrStatsService struct {
*Solr
}

func (s solrStatsService) GetNamespace() string {
return s.Solr.GetNamespace()
}

func (s solrStatsService) ServiceName() string {
return s.OffshootName() + "-stats"
}

func (s solrStatsService) ServiceMonitorName() string {
return s.ServiceName()
}

func (s solrStatsService) ServiceMonitorAdditionalLabels() map[string]string {
return s.OffshootLabels()
}

func (s solrStatsService) Path() string {
return DefaultStatsPath
}

func (s solrStatsService) Scheme() string {
return ""
}

func (s solrStatsService) TLSConfig() *promapi.TLSConfig {
return nil
}

func (s *Solr) StatsService() mona.StatsAccessor {
return &solrStatsService{s}
}

func (s *Solr) StatsServiceLabels() map[string]string {
return s.ServiceLabels(StatsServiceAlias, map[string]string{LabelRole: RoleStats})
}

func (s *Solr) PVCName(alias string) string {
return meta_util.NameWithSuffix(s.Name, alias)
}
Expand Down Expand Up @@ -224,13 +271,13 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) {
if s.Spec.Topology.Data.Replicas == nil {
s.Spec.Topology.Data.Replicas = pointer.Int32P(1)
}

if s.Spec.Topology.Data.PodTemplate.Spec.SecurityContext == nil {
s.Spec.Topology.Data.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{}
}
s.Spec.Topology.Data.PodTemplate.Spec.SecurityContext.FSGroup = slVersion.Spec.SecurityContext.RunAsUser
s.setDefaultContainerSecurityContext(slVersion, &s.Spec.Topology.Data.PodTemplate)
s.setDefaultContainerResourceLimits(&s.Spec.Topology.Data.PodTemplate)

}

if s.Spec.Topology.Overseer != nil {
Expand All @@ -240,7 +287,6 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) {
if s.Spec.Topology.Overseer.Replicas == nil {
s.Spec.Topology.Overseer.Replicas = pointer.Int32P(1)
}

if s.Spec.Topology.Overseer.PodTemplate.Spec.SecurityContext == nil {
s.Spec.Topology.Overseer.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{}
}
Expand All @@ -256,7 +302,6 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) {
if s.Spec.Topology.Coordinator.Replicas == nil {
s.Spec.Topology.Coordinator.Replicas = pointer.Int32P(1)
}

if s.Spec.Topology.Coordinator.PodTemplate.Spec.SecurityContext == nil {
s.Spec.Topology.Coordinator.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{}
}
Expand All @@ -265,15 +310,12 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) {
s.setDefaultContainerResourceLimits(&s.Spec.Topology.Coordinator.PodTemplate)
}
} else {

if s.Spec.Replicas == nil {
s.Spec.Replicas = pointer.Int32P(1)
}

if s.Spec.PodTemplate.Spec.SecurityContext == nil {
s.Spec.PodTemplate.Spec.SecurityContext = &v1.PodSecurityContext{}
}

s.Spec.PodTemplate.Spec.SecurityContext.FSGroup = slVersion.Spec.SecurityContext.RunAsUser
s.setDefaultContainerSecurityContext(slVersion, &s.Spec.PodTemplate)
s.setDefaultContainerResourceLimits(&s.Spec.PodTemplate)
Expand All @@ -292,7 +334,6 @@ func (s *Solr) setDefaultContainerSecurityContext(slVersion *catalog.SolrVersion
}
s.assignDefaultContainerSecurityContext(slVersion, initContainer.SecurityContext)
podTemplate.Spec.InitContainers = coreutil.UpsertContainer(podTemplate.Spec.InitContainers, *initContainer)

container := coreutil.GetContainerByName(podTemplate.Spec.Containers, SolrContainerName)
if container == nil {
container = &v1.Container{
Expand Down Expand Up @@ -329,7 +370,7 @@ func (s *Solr) assignDefaultContainerSecurityContext(slVersion *catalog.SolrVers
func (s *Solr) setDefaultContainerResourceLimits(podTemplate *ofst.PodTemplateSpec) {
dbContainer := coreutil.GetContainerByName(podTemplate.Spec.Containers, SolrContainerName)
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResourcesMemoryIntensive)
apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResourcesCoreAndMemoryIntensiveSolr)
}

initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, SolrInitContainerName)
Expand Down
5 changes: 5 additions & 0 deletions apis/kubedb/v1alpha2/solr_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kmapi "kmodules.xyz/client-go/api/v1"
mona "kmodules.xyz/monitoring-agent-api/api/v1"
ofst "kmodules.xyz/offshoot-api/api/v2"
)

Expand Down Expand Up @@ -122,6 +123,10 @@ type SolrSpec struct {
// +kubebuilder:default={periodSeconds: 20, timeoutSeconds: 10, failureThreshold: 3}
HealthChecker kmapi.HealthCheckSpec `json:"healthChecker"`

// Monitor is used monitor database instance
// +optional
Monitor *mona.AgentSpec `json:"monitor,omitempty"`

// PodPlacementPolicy is the reference of the podPlacementPolicy
// +kubebuilder:default={name: "default"}
// +optional
Expand Down
5 changes: 5 additions & 0 deletions apis/kubedb/v1alpha2/zz_generated.deepcopy.go

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

Loading

0 comments on commit ed0e97c

Please sign in to comment.