Skip to content

Commit

Permalink
Merge pull request #114 from sustainable-computing-io/memleak
Browse files Browse the repository at this point in the history
Reduce memory leak and improve memleak tracing.
  • Loading branch information
trent-s authored Jul 1, 2024
2 parents c331094 + 36446f2 commit 0bb6007
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.21
0.0.22
10 changes: 5 additions & 5 deletions bundle/manifests/susql-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ metadata:
]
capabilities: Basic Install
categories: Monitoring
containerImage: quay.io/sustainable_computing_io/susql_operator:0.0.21
createdAt: "2024-06-27T17:23:07Z"
containerImage: quay.io/sustainable_computing_io/susql_operator:0.0.22
createdAt: "2024-07-01T08:04:51Z"
description: 'Aggregates energy data from pods tagged with SusQL labels '
operators.operatorframework.io/builder: operator-sdk-v1.34.1
operators.operatorframework.io/project_layout: go.kubebuilder.io/v4
repository: https://github.com/sustainable-computing-io/susql-operator
support: https://github.com/sustainable-computing-io/susql-operator/issues
name: susql-operator.v0.0.21
name: susql-operator.v0.0.22
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -224,7 +224,7 @@ spec:
value: :8081
- name: METRICS-BIND-ADDRESS
value: 127.0.0.1:9999
image: quay.io/sustainable_computing_io/susql_operator:0.0.21
image: quay.io/sustainable_computing_io/susql_operator:0.0.22
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
Expand Down Expand Up @@ -328,4 +328,4 @@ spec:
provider:
name: SusQL Operator Contributors
url: https://github.com/sustainable-computing-io/susql-operator
version: 0.0.21
version: 0.0.22
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func main() {
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "cac735ee.ibm.com",
PprofBindAddress: "127.0.0.1:6060",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/sustainable_computing_io/susql_operator
newTag: 0.0.21
newTag: 0.0.22
5 changes: 5 additions & 0 deletions internal/controller/labelgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"context"
"fmt"
coreruntime "runtime"
"strconv"
"time"

Expand Down Expand Up @@ -73,6 +74,10 @@ func (r *LabelGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request)

r.Logger.V(5).Info("[Reconcile] Entered Reconcile().")

var m coreruntime.MemStats
coreruntime.ReadMemStats(&m)
r.Logger.V(5).Info(fmt.Sprintf("Memory: Alloc=%.2f MB TotalAlloc=%.2f MB Sys= %.2f MB NumGC=%v", float32(m.Alloc)/1024.0/1024.0, float32(m.TotalAlloc)/1024.0/1024.0, float32(m.Sys)/1024.0/1024.0, m.NumGC))

// Get label group object to process if it exists
labelGroup := &susqlv1.LabelGroup{}

Expand Down
26 changes: 15 additions & 11 deletions internal/controller/prometheus_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,23 @@ import (
)

var (
maxQueryTime = "1y" // Look back 'maxQueryTime' for the most recent value
maxQueryTime = "1y" // Look back 'maxQueryTime' for the most recent value
keplerRoundTripper http.RoundTripper = nil
susqlRoundTripper http.RoundTripper = nil
)

// Functions to get data from the cluster
func (r *LabelGroupReconciler) GetMostRecentValue(susqlPrometheusQuery string) (float64, error) {
// Return the most recent value found in the table
var roundtripper http.RoundTripper = nil
if strings.HasPrefix(r.KeplerPrometheusUrl, "https://") {
rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
roundtripper = config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls)
if susqlRoundTripper == nil {
if strings.HasPrefix(r.SusQLPrometheusDatabaseUrl, "https://") {
rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
susqlRoundTripper = config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls)
}
}
client, err := api.NewClient(api.Config{
Address: r.SusQLPrometheusDatabaseUrl,
RoundTripper: roundtripper,
RoundTripper: susqlRoundTripper,
})

if err != nil {
Expand Down Expand Up @@ -90,14 +93,15 @@ func (r *LabelGroupReconciler) GetMostRecentValue(susqlPrometheusQuery string) (
}

func (r *LabelGroupReconciler) GetMetricValuesForPodNames(metricName string, podNames []string, namespaceName string) (map[string]float64, error) {
var roundtripper http.RoundTripper = nil
if strings.HasPrefix(r.KeplerPrometheusUrl, "https://") {
rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
roundtripper = config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls)
if keplerRoundTripper == nil {
if strings.HasPrefix(r.KeplerPrometheusUrl, "https://") {
rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
keplerRoundTripper = config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls)
}
}
client, err := api.NewClient(api.Config{
Address: r.KeplerPrometheusUrl,
RoundTripper: roundtripper,
RoundTripper: keplerRoundTripper,
})

if err != nil {
Expand Down

0 comments on commit 0bb6007

Please sign in to comment.