Skip to content

Commit cac604c

Browse files
author
Arvind Thirumurugan
committed
simplify metric-collector
Signed-off-by: Arvind Thirumurugan <arvindth@microsoft.com>
1 parent 164a25d commit cac604c

File tree

12 files changed

+371
-688
lines changed

12 files changed

+371
-688
lines changed

approval-controller-metric-collector/approval-request-controller/apis/metric/v1alpha1/metriccollector_types.go

Lines changed: 0 additions & 146 deletions
This file was deleted.

approval-controller-metric-collector/approval-request-controller/apis/metric/v1alpha1/metriccollectorreport_types.go

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,45 @@ import (
2222

2323
// +genclient
2424
// +kubebuilder:object:root=true
25+
// +kubebuilder:subresource:status
2526
// +kubebuilder:resource:scope="Namespaced",shortName=mcr,categories={fleet,fleet-metrics}
2627
// +kubebuilder:storageversion
27-
// +kubebuilder:printcolumn:JSONPath=`.workloadsMonitored`,name="Workloads",type=integer
28-
// +kubebuilder:printcolumn:JSONPath=`.lastCollectionTime`,name="Last-Collection",type=date
28+
// +kubebuilder:printcolumn:JSONPath=`.status.workloadsMonitored`,name="Workloads",type=integer
29+
// +kubebuilder:printcolumn:JSONPath=`.status.lastCollectionTime`,name="Last-Collection",type=date
2930
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date
3031

31-
// MetricCollectorReport is created by the MetricCollector controller on the hub cluster
32-
// in the fleet-member-{clusterName} namespace to report collected metrics from a member cluster.
33-
// The controller watches MetricCollector objects on the member cluster, collects metrics,
34-
// and syncs the status to the hub as MetricCollectorReport objects.
32+
// MetricCollectorReport is created by the approval-request-controller on the hub cluster
33+
// in the fleet-member-{clusterName} namespace. The metric-collector on the member cluster
34+
// watches these reports and updates their status with collected metrics.
3535
//
3636
// Controller workflow:
37-
// 1. MetricCollector reconciles and collects metrics on member cluster
38-
// 2. Metrics include clusterName from workload_health labels
39-
// 3. Controller creates/updates MetricCollectorReport in fleet-member-{clusterName} namespace on hub
40-
// 4. Report name matches MetricCollector name for easy lookup
37+
// 1. Approval-controller creates MetricCollectorReport with spec on hub
38+
// 2. Metric-collector watches MetricCollectorReport on hub (in fleet-member-{clusterName} namespace)
39+
// 3. Metric-collector queries Prometheus on member cluster
40+
// 4. Metric-collector updates MetricCollectorReport status on hub with collected metrics
4141
//
42-
// Namespace: fleet-member-{clusterName} (extracted from CollectedMetrics[0].ClusterName)
43-
// Name: Same as MetricCollector name
44-
// All metrics in CollectedMetrics are guaranteed to have the same ClusterName.
42+
// Namespace: fleet-member-{clusterName}
43+
// Name: Matches the UpdateRun name
4544
type MetricCollectorReport struct {
4645
metav1.TypeMeta `json:",inline"`
4746
metav1.ObjectMeta `json:"metadata,omitempty"`
4847

49-
// Conditions copied from the MetricCollector status.
50-
// +optional
51-
Conditions []metav1.Condition `json:"conditions,omitempty"`
48+
Spec MetricCollectorReportSpec `json:"spec,omitempty"`
49+
Status MetricCollectorReportStatus `json:"status,omitempty"`
50+
}
51+
52+
// MetricCollectorReportSpec defines the configuration for metric collection.
53+
type MetricCollectorReportSpec struct {
54+
// PrometheusURL is the URL of the Prometheus server on the member cluster
55+
// Example: "http://prometheus.fleet-system.svc.cluster.local:9090"
56+
PrometheusURL string `json:"prometheusUrl"`
57+
}
5258

53-
// ObservedGeneration is the generation most recently observed from the MetricCollector.
59+
// MetricCollectorReportStatus contains the collected metrics from the member cluster.
60+
type MetricCollectorReportStatus struct {
61+
// Conditions represent the latest available observations of the report's state.
5462
// +optional
55-
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
63+
Conditions []metav1.Condition `json:"conditions,omitempty"`
5664

5765
// WorkloadsMonitored is the count of workloads being monitored.
5866
// +optional
@@ -63,13 +71,23 @@ type MetricCollectorReport struct {
6371
LastCollectionTime *metav1.Time `json:"lastCollectionTime,omitempty"`
6472

6573
// CollectedMetrics contains the most recent metrics from each workload.
66-
// All metrics are guaranteed to have the same ClusterName since they're collected from one member cluster.
6774
// +optional
6875
CollectedMetrics []WorkloadMetrics `json:"collectedMetrics,omitempty"`
76+
}
6977

70-
// LastReportTime is when this report was last synced to the hub.
71-
// +optional
72-
LastReportTime *metav1.Time `json:"lastReportTime,omitempty"`
78+
// WorkloadMetrics represents metrics collected from a single workload pod.
79+
type WorkloadMetrics struct {
80+
// Namespace of the workload.
81+
// +required
82+
Namespace string `json:"namespace"`
83+
84+
// WorkloadName from the workload_health metric label.
85+
// +required
86+
WorkloadName string `json:"workloadName"`
87+
88+
// Health indicates if the workload is healthy (true=healthy, false=unhealthy).
89+
// +required
90+
Health bool `json:"health"`
7391
}
7492

7593
// +kubebuilder:object:root=true

approval-controller-metric-collector/approval-request-controller/apis/metric/v1alpha1/zz_generated.deepcopy.go

Lines changed: 9 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)