Skip to content

Commit e6e4429

Browse files
committed
feat: Database_observability: support Azure cloud provider config data
Add configuration block `database_observability.cloud_provider.azure` to support Azure database instances in addition to existing AWS support. When data is provided in this block, the corresponding labels are populated.
1 parent d9a7e87 commit e6e4429

File tree

13 files changed

+207
-8
lines changed

13 files changed

+207
-8
lines changed

docs/sources/reference/components/database_observability/database_observability.mysql.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ You can use the following blocks with `database_observability.mysql`:
5555
|--------------------------------------|---------------------------------------------------|----------|
5656
| [`cloud_provider`][cloud_provider] | Provide Cloud Provider information. | no |
5757
| `cloud_provider` > [`aws`][aws] | Provide AWS database host information. | no |
58+
| `cloud_provider` > [`azure`][azure] | Provide Azure database host information. | no |
5859
| [`setup_consumers`][setup_consumers] | Configure the `setup_consumers` collector. | no |
5960
| [`setup_actors`][setup_actors] | Configure the `setup_actors` collector. | no |
6061
| [`query_details`][query_details] | Configure the queries collector. | no |
@@ -69,6 +70,7 @@ For example, `cloud_provider` > `aws` refers to a `aws` block defined inside an
6970

7071
[cloud_provider]: #cloud_provider
7172
[aws]: #aws
73+
[azure]: #azure
7274
[setup_consumers]: #setup_consumers
7375
[query_details]: #query_details
7476
[schema_details]: #schema_details
@@ -94,6 +96,16 @@ The `aws` block supplies the [ARN](https://docs.aws.amazon.com/IAM/latest/UserGu
9496
|-------|----------|---------------------------------------------------------|---------|----------|
9597
| `arn` | `string` | The ARN associated with the database under observation. | | yes |
9698

99+
### `azure`
100+
101+
The `azure` block supplies the identifying information for the database being monitored.
102+
103+
| Name | Type | Description | Default | Required |
104+
|-------------------|----------|------------------------------------------------------|---------|----------|
105+
| `subscription_id` | `string` | The Subscription ID for your Azure account. | | yes |
106+
| `resource_group` | `string` | The Resource Group that holds the database resource. | | yes |
107+
| `server_name` | `string` | The database server name. | | no |
108+
97109
### `setup_consumers`
98110

99111
| Name | Type | Description | Default | Required |

docs/sources/reference/components/database_observability/database_observability.postgres.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ You can use the following blocks with `database_observability.postgres`:
5151
|------------------------------------|---------------------------------------------------|----------|
5252
| [`cloud_provider`][cloud_provider] | Provide Cloud Provider information. | no |
5353
| `cloud_provider` > [`aws`][aws] | Provide AWS database host information. | no |
54+
| `cloud_provider` > [`azure`][azure] | Provide Azure database host information. | no |
5455
| [`query_details`][query_details] | Configure the queries collector. | no |
5556
| [`query_samples`][query_samples] | Configure the query samples collector. | no |
5657
| [`schema_details`][schema_details] | Configure the schema and table details collector. | no |
@@ -62,6 +63,7 @@ For example, `cloud_provider` > `aws` refers to a `aws` block defined inside an
6263

6364
[cloud_provider]: #cloud_provider
6465
[aws]: #aws
66+
[azure]: #azure
6567
[query_details]: #query_details
6668
[query_samples]: #query_samples
6769
[schema_details]: #schema_details
@@ -84,6 +86,16 @@ The `aws` block supplies the [ARN](https://docs.aws.amazon.com/IAM/latest/UserGu
8486
|-------|----------|---------------------------------------------------------|---------|----------|
8587
| `arn` | `string` | The ARN associated with the database under observation. | | yes |
8688

89+
### `azure`
90+
91+
The `azure` block supplies the identifying information for the database being monitored.
92+
93+
| Name | Type | Description | Default | Required |
94+
|-------------------|----------|------------------------------------------------------|---------|----------|
95+
| `subscription_id` | `string` | The Subscription ID for your Azure account. | | yes |
96+
| `resource_group` | `string` | The Resource Group that holds the database resource. | | yes |
97+
| `server_name` | `string` | The database server name. | | no |
98+
8799
### `query_details`
88100

89101
| Name | Type | Description | Default | Required |

internal/component/database_observability/cloud_provider.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ type CloudProvider struct {
1212
type AWSCloudProviderInfo struct {
1313
ARN arn.ARN
1414
}
15+
1516
type AzureCloudProviderInfo struct {
16-
Resource string
17+
Resource string
18+
SubscriptionID string
19+
ResourceGroup string
1720
}

internal/component/database_observability/mysql/cloud_provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ func populateCloudProviderFromConfig(config *CloudProvider) (*database_observabi
2727
ARN: arn,
2828
}
2929
}
30+
if config.Azure != nil {
31+
cloudProvider.Azure = &database_observability.AzureCloudProviderInfo{
32+
SubscriptionID: config.Azure.SubscriptionID,
33+
ResourceGroup: config.Azure.ResourceGroup,
34+
Resource: config.Azure.ServerName,
35+
}
36+
}
3037
return &cloudProvider, nil
3138
}
3239

internal/component/database_observability/mysql/collector/connection_info.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func (c *ConnectionInfo) Start(ctx context.Context) error {
8282
if c.CloudProvider.Azure != nil {
8383
providerName = "azure"
8484
dbInstanceIdentifier = c.CloudProvider.Azure.Resource
85+
providerRegion = c.CloudProvider.Azure.ResourceGroup
86+
providerAccount = c.CloudProvider.Azure.SubscriptionID
8587
}
8688
} else {
8789
cfg, err := mysql.ParseDSN(c.DSN)

internal/component/database_observability/mysql/collector/connection_info_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ func TestConnectionInfo(t *testing.T) {
6060
{
6161
name: "Azure with cloud provider info supplied",
6262
dsn: "user:pass@tcp(products-db.mysql.database.azure.com:3306)/schema",
63-
engineVersion: "15.4",
63+
engineVersion: "8.0.32",
6464
cloudProvider: &database_observability.CloudProvider{
6565
Azure: &database_observability.AzureCloudProviderInfo{
66-
Resource: "products-db",
66+
Resource: "products-db",
67+
SubscriptionID: "sub-12345-abcde",
68+
ResourceGroup: "my-resource-group",
6769
},
6870
},
69-
expectedMetrics: fmt.Sprintf(baseExpectedMetrics, "products-db", "mysql", "15.4", "unknown", "azure", "unknown"),
71+
expectedMetrics: fmt.Sprintf(baseExpectedMetrics, "products-db", "mysql", "8.0.32", "sub-12345-abcde", "azure", "my-resource-group"),
7072
},
7173
{
7274
name: "Azure flexibleservers dsn",

internal/component/database_observability/mysql/component.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,20 @@ type Arguments struct {
7474
}
7575

7676
type CloudProvider struct {
77-
AWS *AWSCloudProviderInfo `alloy:"aws,block,optional"`
77+
AWS *AWSCloudProviderInfo `alloy:"aws,block,optional"`
78+
Azure *AzureCloudProviderInfo `alloy:"azure,block,optional"`
7879
}
7980

8081
type AWSCloudProviderInfo struct {
8182
ARN string `alloy:"arn,attr"`
8283
}
8384

85+
type AzureCloudProviderInfo struct {
86+
SubscriptionID string `alloy:"subscription_id,attr"`
87+
ResourceGroup string `alloy:"resource_group,attr"`
88+
ServerName string `alloy:"server_name,attr,optional"`
89+
}
90+
8491
type QueryTablesArguments struct {
8592
CollectInterval time.Duration `alloy:"collect_interval,attr,optional"`
8693
}

internal/component/database_observability/mysql/component_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,56 @@ func Test_parseCloudProvider(t *testing.T) {
9292

9393
assert.Equal(t, "arn:aws:rds:some-region:some-account:db:some-db-instance", args.CloudProvider.AWS.ARN)
9494
})
95+
96+
t.Run("parse azure cloud provider block with all fields", func(t *testing.T) {
97+
exampleDBO11yAlloyConfig := `
98+
data_source_name = ""
99+
forward_to = []
100+
targets = []
101+
cloud_provider {
102+
azure {
103+
subscription_id = "sub-12345-abcde"
104+
resource_group = "my-resource-group"
105+
server_name = "my-mysql-server"
106+
}
107+
}
108+
`
109+
110+
var args Arguments
111+
err := syntax.Unmarshal([]byte(exampleDBO11yAlloyConfig), &args)
112+
require.NoError(t, err)
113+
114+
require.NotNil(t, args.CloudProvider)
115+
require.NotNil(t, args.CloudProvider.Azure)
116+
assert.Equal(t, "sub-12345-abcde", args.CloudProvider.Azure.SubscriptionID)
117+
assert.Equal(t, "my-resource-group", args.CloudProvider.Azure.ResourceGroup)
118+
assert.Equal(t, "my-mysql-server", args.CloudProvider.Azure.ServerName)
119+
})
120+
121+
t.Run("parse azure cloud provider block without optional server_name", func(t *testing.T) {
122+
exampleDBO11yAlloyConfig := `
123+
data_source_name = ""
124+
forward_to = []
125+
targets = []
126+
cloud_provider {
127+
azure {
128+
subscription_id = "sub-12345-abcde"
129+
resource_group = "my-resource-group"
130+
}
131+
}
132+
`
133+
134+
var args Arguments
135+
err := syntax.Unmarshal([]byte(exampleDBO11yAlloyConfig), &args)
136+
require.NoError(t, err)
137+
138+
require.NotNil(t, args.CloudProvider)
139+
require.NotNil(t, args.CloudProvider.Azure)
140+
assert.Equal(t, "sub-12345-abcde", args.CloudProvider.Azure.SubscriptionID)
141+
assert.Equal(t, "my-resource-group", args.CloudProvider.Azure.ResourceGroup)
142+
assert.Empty(t, args.CloudProvider.Azure.ServerName)
143+
})
144+
95145
t.Run("empty cloud provider block", func(t *testing.T) {
96146
exampleDBO11yAlloyConfig := `
97147
data_source_name = ""

internal/component/database_observability/postgres/cloud_provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ func populateCloudProviderFromConfig(config *CloudProvider) (*database_observabi
2626
ARN: arn,
2727
}
2828
}
29+
if config.Azure != nil {
30+
cloudProvider.Azure = &database_observability.AzureCloudProviderInfo{
31+
SubscriptionID: config.Azure.SubscriptionID,
32+
ResourceGroup: config.Azure.ResourceGroup,
33+
Resource: config.Azure.ServerName,
34+
}
35+
}
2936
return &cloudProvider, nil
3037
}
3138

internal/component/database_observability/postgres/collector/connection_info.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func (c *ConnectionInfo) Start(ctx context.Context) error {
8383
if c.CloudProvider.Azure != nil {
8484
providerName = "azure"
8585
dbInstanceIdentifier = c.CloudProvider.Azure.Resource
86+
providerRegion = c.CloudProvider.Azure.ResourceGroup
87+
providerAccount = c.CloudProvider.Azure.SubscriptionID
8688
}
8789
} else {
8890
parts, err := ParseURL(c.DSN)

0 commit comments

Comments
 (0)