@@ -114,7 +114,7 @@ func (am *annotatedMetric) asPrometheus() (prometheus.Metric, error) {
114
114
extraLabels = am .Labels
115
115
)
116
116
117
- for _ , label := range am . aggregateByLabels {
117
+ for _ , label := range baseLabelNames {
118
118
val , err := am .getFieldByLabel (label )
119
119
if err != nil {
120
120
return nil , err
@@ -147,13 +147,13 @@ func (am *annotatedMetric) asPrometheus() (prometheus.Metric, error) {
147
147
func (am * annotatedMetric ) getFieldByLabel (label string ) (string , error ) {
148
148
var labelVal string
149
149
switch label {
150
- case agentmetrics .WorkspaceNameLabel :
150
+ case agentmetrics .LabelWorkspaceName :
151
151
labelVal = am .workspaceName
152
- case agentmetrics .TemplateNameLabel :
152
+ case agentmetrics .LabelTemplateName :
153
153
labelVal = am .templateName
154
- case agentmetrics .AgentNameLabel :
154
+ case agentmetrics .LabelAgentName :
155
155
labelVal = am .agentName
156
- case agentmetrics .UsernameLabel :
156
+ case agentmetrics .LabelUsername :
157
157
labelVal = am .username
158
158
default :
159
159
return "" , xerrors .Errorf ("unexpected label: %q" , label )
@@ -162,7 +162,7 @@ func (am *annotatedMetric) getFieldByLabel(label string) (string, error) {
162
162
return labelVal , nil
163
163
}
164
164
165
- func (am * annotatedMetric ) clone () annotatedMetric {
165
+ func (am * annotatedMetric ) shallowCopy () annotatedMetric {
166
166
stats := & agentproto.Stats_Metric {
167
167
Name : am .Name ,
168
168
Type : am .Type ,
@@ -273,7 +273,7 @@ func (a *labelAggregator) aggregate(am annotatedMetric, labels []string) error {
273
273
metric , found := a .metrics [key ]
274
274
if ! found {
275
275
// Take a copy of the given annotatedMetric because it may be manipulated later and contains pointers.
276
- metric = am .clone ()
276
+ metric = am .shallowCopy ()
277
277
}
278
278
279
279
// Store the metric.
@@ -337,8 +337,9 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
337
337
338
338
// If custom aggregation labels have not been chosen, generate Prometheus metrics without any pre-aggregation.
339
339
// This results in higher cardinality, but may be desirable in larger deployments.
340
+ //
340
341
// Default behavior.
341
- if len (ma .aggregateByLabels ) == 0 {
342
+ if len (ma .aggregateByLabels ) == len ( agentmetrics . LabelAll ) {
342
343
for _ , m := range ma .store {
343
344
// Aggregate by all available metrics.
344
345
m .aggregateByLabels = defaultAgentMetricsLabels
@@ -402,7 +403,7 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
402
403
func (* MetricsAggregator ) Describe (_ chan <- * prometheus.Desc ) {
403
404
}
404
405
405
- var defaultAgentMetricsLabels = []string {agentmetrics .UsernameLabel , agentmetrics .WorkspaceNameLabel , agentmetrics .AgentNameLabel , agentmetrics .TemplateNameLabel }
406
+ var defaultAgentMetricsLabels = []string {agentmetrics .LabelUsername , agentmetrics .LabelWorkspaceName , agentmetrics .LabelAgentName , agentmetrics .LabelTemplateName }
406
407
407
408
// AgentMetricLabels are the labels used to decorate an agent's metrics.
408
409
// This list should match the list of labels in agentMetricsLabels.
0 commit comments