Skip to content

Commit 64e55f3

Browse files
authored
[TA] One service per Target Allocator (#259)
* added one-service per TA
1 parent a877192 commit 64e55f3

12 files changed

+32
-30
lines changed

internal/manifests/collector/config_replace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func ReplacePrometheusConfig(instance v1alpha1.AmazonCloudWatchAgent) (string, e
8181
}
8282

8383
if featuregate.EnableTargetAllocatorRewrite.IsEnabled() {
84-
updPromCfgMap, getCfgPromErr := ta.AddTAConfigToPromConfig(promCfgMap, naming.TAService())
84+
updPromCfgMap, getCfgPromErr := ta.AddTAConfigToPromConfig(promCfgMap, naming.TAService(instance.Name))
8585
if getCfgPromErr != nil {
8686
return "", getCfgPromErr
8787
}
@@ -94,7 +94,7 @@ func ReplacePrometheusConfig(instance v1alpha1.AmazonCloudWatchAgent) (string, e
9494
return string(out), nil
9595
}
9696

97-
updPromCfgMap, err := ta.AddHTTPSDConfigToPromConfig(promCfgMap, naming.TAService())
97+
updPromCfgMap, err := ta.AddHTTPSDConfigToPromConfig(promCfgMap, naming.TAService(instance.Name))
9898
if err != nil {
9999
return "", err
100100
}

internal/manifests/collector/config_replace_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestPrometheusParser(t *testing.T) {
8282
for _, scrapeConfig := range cfg.PromConfig.ScrapeConfigs {
8383
assert.Len(t, scrapeConfig.ServiceDiscoveryConfigs, 1)
8484
assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].Name(), "http")
85-
assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].(*http.SDConfig).URL, "http://target-allocator-service:80/jobs/"+scrapeConfig.JobName+"/targets")
85+
assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].(*http.SDConfig).URL, fmt.Sprintf("https://%s-target-allocator-service:80/jobs/", param.OtelCol.Name)+scrapeConfig.JobName+"/targets")
8686
expectedMap[scrapeConfig.JobName] = true
8787
}
8888
for k := range expectedMap {
@@ -106,7 +106,7 @@ func TestPrometheusParser(t *testing.T) {
106106
assert.NotContains(t, prometheusConfig, "scrape_configs")
107107

108108
expectedTAConfig := map[interface{}]interface{}{
109-
"endpoint": "http://target-allocator-service:80",
109+
"endpoint": fmt.Sprintf("https://%s-target-allocator-service:80", param.OtelCol.Name),
110110
"interval": "30s",
111111
}
112112
assert.Equal(t, expectedTAConfig, promCfgMap["target_allocator"])
@@ -160,7 +160,7 @@ func TestPrometheusParser(t *testing.T) {
160160
assert.NotContains(t, prometheusConfig, "scrape_configs")
161161

162162
expectedTAConfig := map[interface{}]interface{}{
163-
"endpoint": "http://target-allocator-service:80",
163+
"endpoint": fmt.Sprintf("https://%s-target-allocator-service:80", param.OtelCol.Name),
164164
"interval": "30s",
165165
}
166166
assert.Equal(t, expectedTAConfig, promCfgMap["target_allocator"])
@@ -305,7 +305,7 @@ func TestReplacePrometheusConfig(t *testing.T) {
305305
scrape_configs:
306306
- honor_labels: true
307307
http_sd_configs:
308-
- url: http://target-allocator-service:80/jobs/service-x/targets
308+
- url: https://test-target-allocator-service:80/jobs/service-x/targets
309309
job_name: service-x
310310
metric_relabel_configs:
311311
- action: keep
@@ -358,7 +358,7 @@ func TestReplacePrometheusConfig(t *testing.T) {
358358
scrape_interval: 1m
359359
scrape_timeout: 10s
360360
target_allocator:
361-
endpoint: http://target-allocator-service:80
361+
endpoint: https://test-target-allocator-service:80
362362
interval: 30s
363363
`
364364

internal/manifests/collector/configmap_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func TestDesiredPrometheusConfigMap(t *testing.T) {
139139
"prometheus.yaml": `config:
140140
scrape_configs:
141141
- http_sd_configs:
142-
- url: http://target-allocator-service:80/jobs/cloudwatch-agent/targets
142+
- url: https://test-target-allocator-service:80/jobs/cloudwatch-agent/targets
143143
job_name: cloudwatch-agent
144144
scrape_interval: 10s
145145
`,
@@ -188,10 +188,10 @@ func TestDesiredPrometheusConfigMap(t *testing.T) {
188188
"prometheus.yaml": `config:
189189
scrape_configs:
190190
- http_sd_configs:
191-
- url: http://target-allocator-service:80/jobs/serviceMonitor%2Ftest%2Ftest%2F0/targets
191+
- url: https://test-target-allocator-service:80/jobs/serviceMonitor%2Ftest%2Ftest%2F0/targets
192192
job_name: serviceMonitor/test/test/0
193193
target_allocator:
194-
endpoint: http://target-allocator-service:80
194+
endpoint: https://test-target-allocator-service:80
195195
http_sd_config:
196196
refresh_interval: 60s
197197
interval: 30s
@@ -239,7 +239,7 @@ target_allocator:
239239
expectedData := map[string]string{
240240
"prometheus.yaml": `config: {}
241241
target_allocator:
242-
endpoint: http://target-allocator-service:80
242+
endpoint: https://test-target-allocator-service:80
243243
interval: 30s
244244
`,
245245
}

internal/manifests/collector/testdata/config_expected_targetallocator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ config:
44
scrape_interval: 1m
55
scrape_timeout: 10s
66
target_allocator:
7-
endpoint: http://target-allocator-service:80
7+
endpoint: https://test-target-allocator-service:80
88
interval: 30s

internal/manifests/collector/testdata/http_sd_config_servicemonitor_test_ta_set.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config:
1111
- files:
1212
- file2.json
1313
target_allocator:
14-
endpoint: http://target-allocator-service:80
14+
endpoint: https://test-target-allocator-service:80
1515
interval: 30s
1616
http_sd_config:
1717
refresh_interval: 60s

internal/manifests/collector/testdata/http_sd_config_ta_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ config:
77
labels:
88
my: label
99
target_allocator:
10-
endpoint: http://test-sd-target-allocator:80
10+
endpoint: https://test-sd-target-allocator:80
1111
interval: 60s

internal/manifests/collector/testdata/relabel_config_expected_with_sd_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ config:
66
scrape_configs:
77
- honor_labels: true
88
http_sd_configs:
9-
- url: http://target-allocator-service:80/jobs/service-x/targets
9+
- url: https://test-target-allocator-service:80/jobs/service-x/targets
1010
job_name: service-x
1111
metric_relabel_configs:
1212
- action: keep

internal/manifests/targetallocator/adapters/config_to_prom_config_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func TestAddHTTPSDConfigToPromConfig(t *testing.T) {
181181
}
182182

183183
func TestAddTAConfigToPromConfig(t *testing.T) {
184+
collectorName := "test-collector"
184185
t.Run("should return expected prom config map with TA config", func(t *testing.T) {
185186
cfg := map[interface{}]interface{}{
186187
"config": map[interface{}]interface{}{
@@ -202,12 +203,12 @@ func TestAddTAConfigToPromConfig(t *testing.T) {
202203
expectedResult := map[interface{}]interface{}{
203204
"config": map[interface{}]interface{}{},
204205
"target_allocator": map[interface{}]interface{}{
205-
"endpoint": "https://target-allocator-service:80",
206+
"endpoint": fmt.Sprintf("https://%s-target-allocator-service:80", collectorName),
206207
"interval": "30s",
207208
},
208209
}
209210

210-
result, err := ta.AddTAConfigToPromConfig(cfg, naming.TAService())
211+
result, err := ta.AddTAConfigToPromConfig(cfg, naming.TAService(collectorName))
211212

212213
assert.NoError(t, err)
213214
assert.Equal(t, expectedResult, result)
@@ -235,7 +236,7 @@ func TestAddTAConfigToPromConfig(t *testing.T) {
235236

236237
for _, tc := range testCases {
237238
t.Run(tc.name, func(t *testing.T) {
238-
_, err := ta.AddTAConfigToPromConfig(tc.cfg, naming.TAService())
239+
_, err := ta.AddTAConfigToPromConfig(tc.cfg, naming.TAService(collectorName))
239240

240241
assert.Error(t, err)
241242
assert.EqualError(t, err, tc.errText)

internal/manifests/targetallocator/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
"github.com/aws/amazon-cloudwatch-agent-operator/internal/config"
1212
"github.com/aws/amazon-cloudwatch-agent-operator/internal/naming"
1313
)
14+
1415
// This has to be a constant so that TA container code can access it as well
1516
const TACertMountPath = "/etc/amazon-cloudwatch-target-allocator-cert"
17+
1618
// Container builds a container for the given TargetAllocator.
1719
func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.AmazonCloudWatchAgent) corev1.Container {
1820
image := otelcol.Spec.TargetAllocator.Image

internal/manifests/targetallocator/container_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ func TestContainerHasEnvVars(t *testing.T) {
176176
SubPathExpr: "",
177177
},
178178
{
179-
Name: "ta-secret",
180-
ReadOnly: true,
181-
MountPath: TACertMountPath,
179+
Name: "ta-secret",
180+
ReadOnly: true,
181+
MountPath: TACertMountPath,
182182
},
183183
},
184184
Ports: []corev1.ContainerPort{
@@ -233,9 +233,9 @@ func TestContainerDoesNotOverrideEnvVars(t *testing.T) {
233233
SubPathExpr: "",
234234
},
235235
{
236-
Name: "ta-secret",
237-
ReadOnly: true,
238-
MountPath: TACertMountPath,
236+
Name: "ta-secret",
237+
ReadOnly: true,
238+
MountPath: TACertMountPath,
239239
},
240240
},
241241
Ports: []corev1.ContainerPort{

0 commit comments

Comments
 (0)