-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metrics and http probes have been added (#3)
* Added vendor to gitignore * Added metrics module for deployments * Added concurency for metrics and delete service * Run metrics and cleanup services concurently, modify helm charts * Changed chart and app versions to 0.1.0 * Modyfied README --------- Co-authored-by: Valentin Khramtsov <[email protected]>
- Loading branch information
Showing
11 changed files
with
209 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ .Release.Name }} | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{- include "charts.labels" . | nindent 4 }} | ||
annotations: | ||
{{- toYaml .Values.service.annotations | nindent 4 }} | ||
spec: | ||
type: {{ .Values.service.type }} | ||
ports: | ||
- port: {{ .Values.service.port }} | ||
targetPort: {{ .Values.service.port }} | ||
protocol: TCP | ||
name: "metrics" | ||
selector: | ||
{{- include "charts.selectorLabels" . | nindent 4 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"sync" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
var ( | ||
mutex = sync.Mutex{} | ||
) | ||
|
||
func FetchAndUpdateDeploymentMetrics( | ||
ctx context.Context, | ||
clientset *kubernetes.Clientset, | ||
namespace string, | ||
deploymentMetrics *prometheus.GaugeVec) { | ||
secrets, err := clientset.CoreV1().Secrets(namespace).List(ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
log.Println("Error fetching secrets:", err) | ||
return | ||
} | ||
|
||
mutex.Lock() | ||
defer mutex.Unlock() | ||
|
||
for _, secret := range secrets.Items { | ||
if secret.Type != "helm.sh/release.v1" || secret.Labels["version"] != "1" { | ||
continue | ||
} | ||
deploymentMetrics.WithLabelValues(secret.Labels["name"]).Set(float64(time.Now().Sub(secret.CreationTimestamp.Time).Seconds())) | ||
} | ||
} |