mirror of
https://github.com/SigNoz/signoz.git
synced 2026-04-28 22:50:32 +01:00
* refactor: moving types to cloud provider specific namespace/pkg * refactor: separating cloud provider types * refactor: using upper case key for AWS * feat: adding cloud integration azure types * feat: adding azure services * refactor: updating omitempty tags * refactor: updating azure integration config * feat: completing azure types * refactor: lint issues * feat: adding service definitions for azure * refactor: update service names for Azure Blob Storage telemetry * refactor: updating definitions with metrics and strategy * refactor: updating command key * fix: handle optional connection URL in AWS integration * feat: wip * refactor: updating strategy struct * refactor: updating telemetry strategy * refactor: updating connection artifact struct * refactor: updating blob storage service name * refactor: updating azure blob storage service name * refactor: update Azure service identifiers * refactor: updating service defs * fix: update integration account ID and add agent version to Azure CLI and PowerShell commands * refactor: updating deny settings mode * refactor: updating types * refactor: adding missing case for azure service update * feat: implement Azure connection commands and add unit tests * refactor: using template for Azure connection artifact creation and update tests
107 lines
3.5 KiB
Go
107 lines
3.5 KiB
Go
package implcloudprovider
|
|
|
|
import (
|
|
"context"
|
|
"sort"
|
|
|
|
"github.com/SigNoz/signoz/pkg/modules/cloudintegration"
|
|
"github.com/SigNoz/signoz/pkg/types/cloudintegrationtypes"
|
|
)
|
|
|
|
type azurecloudprovider struct {
|
|
serviceDefinitions cloudintegrationtypes.ServiceDefinitionStore
|
|
}
|
|
|
|
func NewAzureCloudProvider(defStore cloudintegrationtypes.ServiceDefinitionStore) cloudintegration.CloudProviderModule {
|
|
return &azurecloudprovider{
|
|
serviceDefinitions: defStore,
|
|
}
|
|
}
|
|
|
|
func (provider *azurecloudprovider) GetConnectionArtifact(ctx context.Context, account *cloudintegrationtypes.Account, req *cloudintegrationtypes.GetConnectionArtifactRequest) (*cloudintegrationtypes.ConnectionArtifact, error) {
|
|
connectionArtifact, err := cloudintegrationtypes.NewAzureConnectionArtifact(account.ID, req.Config.AgentVersion, req.Credentials, req.Config.Azure)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &cloudintegrationtypes.ConnectionArtifact{
|
|
Azure: connectionArtifact,
|
|
}, nil
|
|
}
|
|
|
|
func (provider *azurecloudprovider) ListServiceDefinitions(ctx context.Context) ([]*cloudintegrationtypes.ServiceDefinition, error) {
|
|
return provider.serviceDefinitions.List(ctx, cloudintegrationtypes.CloudProviderTypeAzure)
|
|
}
|
|
|
|
func (provider *azurecloudprovider) GetServiceDefinition(ctx context.Context, serviceID cloudintegrationtypes.ServiceID) (*cloudintegrationtypes.ServiceDefinition, error) {
|
|
serviceDef, err := provider.serviceDefinitions.Get(ctx, cloudintegrationtypes.CloudProviderTypeAzure, serviceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// override cloud integration dashboard id.
|
|
for index, dashboard := range serviceDef.Assets.Dashboards {
|
|
serviceDef.Assets.Dashboards[index].ID = cloudintegrationtypes.GetCloudIntegrationDashboardID(cloudintegrationtypes.CloudProviderTypeAzure, serviceID.StringValue(), dashboard.ID)
|
|
}
|
|
|
|
return serviceDef, nil
|
|
}
|
|
|
|
func (provider *azurecloudprovider) BuildIntegrationConfig(
|
|
ctx context.Context,
|
|
account *cloudintegrationtypes.Account,
|
|
services []*cloudintegrationtypes.StorableCloudIntegrationService,
|
|
) (*cloudintegrationtypes.ProviderIntegrationConfig, error) {
|
|
sort.Slice(services, func(i, j int) bool {
|
|
return services[i].Type.StringValue() < services[j].Type.StringValue()
|
|
})
|
|
|
|
var strategies []*cloudintegrationtypes.AzureTelemetryCollectionStrategy
|
|
|
|
for _, storedSvc := range services {
|
|
svcCfg, err := cloudintegrationtypes.NewServiceConfigFromJSON(cloudintegrationtypes.CloudProviderTypeAzure, storedSvc.Config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
svcDef, err := provider.GetServiceDefinition(ctx, storedSvc.Type)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
strategy := svcDef.TelemetryCollectionStrategy.Azure
|
|
if strategy == nil {
|
|
continue
|
|
}
|
|
|
|
logsEnabled := svcCfg.IsLogsEnabled(cloudintegrationtypes.CloudProviderTypeAzure)
|
|
metricsEnabled := svcCfg.IsMetricsEnabled(cloudintegrationtypes.CloudProviderTypeAzure)
|
|
|
|
if !logsEnabled && !metricsEnabled {
|
|
continue
|
|
}
|
|
|
|
entry := &cloudintegrationtypes.AzureTelemetryCollectionStrategy{
|
|
ResourceProvider: strategy.ResourceProvider,
|
|
ResourceType: strategy.ResourceType,
|
|
}
|
|
|
|
if metricsEnabled && strategy.Metrics != nil {
|
|
entry.Metrics = strategy.Metrics
|
|
}
|
|
|
|
if logsEnabled && strategy.Logs != nil {
|
|
entry.Logs = strategy.Logs
|
|
}
|
|
|
|
strategies = append(strategies, entry)
|
|
}
|
|
|
|
return &cloudintegrationtypes.ProviderIntegrationConfig{
|
|
Azure: cloudintegrationtypes.NewAzureIntegrationConfig(
|
|
account.Config.Azure.DeploymentRegion,
|
|
account.Config.Azure.ResourceGroups,
|
|
strategies,
|
|
),
|
|
}, nil
|
|
}
|