2025-01-10 18:43:35 +05:30
package cloudintegrations
import (
"fmt"
2025-01-16 17:36:09 +05:30
2025-03-20 21:01:41 +05:30
"github.com/SigNoz/signoz/pkg/types"
2025-01-10 18:43:35 +05:30
)
2025-01-16 17:36:09 +05:30
type CloudServiceSummary struct {
Id string ` json:"id" `
Title string ` json:"title" `
Icon string ` json:"icon" `
// Present only if the service has been configured in the
// context of a cloud provider account.
2025-04-15 21:05:36 +05:30
Config * types . CloudServiceConfig ` json:"config,omitempty" `
2025-01-16 17:36:09 +05:30
}
type CloudServiceDetails struct {
CloudServiceSummary
Overview string ` json:"overview" ` // markdown
Assets CloudServiceAssets ` json:"assets" `
SupportedSignals SupportedSignals ` json:"supported_signals" `
DataCollected DataCollectedForService ` json:"data_collected" `
ConnectionStatus * CloudServiceConnectionStatus ` json:"status,omitempty" `
2025-02-03 20:52:15 +05:30
TelemetryCollectionStrategy * CloudTelemetryCollectionStrategy ` json:"telemetry_collection_strategy" `
2025-01-16 17:36:09 +05:30
}
type CloudServiceAssets struct {
2025-02-13 19:45:51 +05:30
Dashboards [ ] CloudServiceDashboard ` json:"dashboards" `
}
type CloudServiceDashboard struct {
2025-03-12 17:18:11 +05:30
Id string ` json:"id" `
Url string ` json:"url" `
Title string ` json:"title" `
Description string ` json:"description" `
Image string ` json:"image" `
Definition * types . DashboardData ` json:"definition,omitempty" `
2025-01-16 17:36:09 +05:30
}
type SupportedSignals struct {
Logs bool ` json:"logs" `
Metrics bool ` json:"metrics" `
}
type DataCollectedForService struct {
Logs [ ] CollectedLogAttribute ` json:"logs" `
Metrics [ ] CollectedMetric ` json:"metrics" `
}
type CollectedLogAttribute struct {
Name string ` json:"name" `
Path string ` json:"path" `
Type string ` json:"type" `
}
type CollectedMetric struct {
Name string ` json:"name" `
Type string ` json:"type" `
Unit string ` json:"unit" `
Description string ` json:"description" `
}
type CloudServiceConnectionStatus struct {
Logs * SignalConnectionStatus ` json:"logs" `
Metrics * SignalConnectionStatus ` json:"metrics" `
}
type SignalConnectionStatus struct {
LastReceivedTsMillis int64 ` json:"last_received_ts_ms" ` // epoch milliseconds
LastReceivedFrom string ` json:"last_received_from" ` // resource identifier
}
2025-02-03 20:52:15 +05:30
type CloudTelemetryCollectionStrategy struct {
Provider string ` json:"provider" `
AWSMetrics * AWSMetricsCollectionStrategy ` json:"aws_metrics,omitempty" `
AWSLogs * AWSLogsCollectionStrategy ` json:"aws_logs,omitempty" `
}
func NewCloudTelemetryCollectionStrategy ( provider string ) ( * CloudTelemetryCollectionStrategy , error ) {
if provider == "aws" {
return & CloudTelemetryCollectionStrategy {
Provider : "aws" ,
AWSMetrics : & AWSMetricsCollectionStrategy {
CloudwatchMetricsStreamFilters : [ ] CloudwatchMetricStreamFilter { } ,
} ,
AWSLogs : & AWSLogsCollectionStrategy {
CloudwatchLogsSubscriptions : [ ] CloudwatchLogsSubscriptionConfig { } ,
} ,
} , nil
}
return nil , fmt . Errorf ( "unsupported cloud provider: %s" , provider )
}
// Helper for accumulating strategies for enabled services.
func ( cs * CloudTelemetryCollectionStrategy ) AddServiceStrategy (
svcStrategy * CloudTelemetryCollectionStrategy ,
logsEnabled bool ,
metricsEnabled bool ,
) error {
if svcStrategy . Provider != cs . Provider {
return fmt . Errorf (
"can't add %s service strategy to strategy for %s" ,
svcStrategy . Provider , cs . Provider ,
)
}
if cs . Provider == "aws" {
if logsEnabled {
cs . AWSLogs . AddServiceStrategy ( svcStrategy . AWSLogs )
}
if metricsEnabled {
cs . AWSMetrics . AddServiceStrategy ( svcStrategy . AWSMetrics )
}
return nil
}
return fmt . Errorf ( "unsupported cloud provider: %s" , cs . Provider )
}
type AWSMetricsCollectionStrategy struct {
// to be used as https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudwatch-metricstream.html#cfn-cloudwatch-metricstream-includefilters
CloudwatchMetricsStreamFilters [ ] CloudwatchMetricStreamFilter ` json:"cloudwatch_metric_stream_filters" `
}
type CloudwatchMetricStreamFilter struct {
// json tags here are in the shape expected by AWS API as detailed at
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudwatch-metricstream-metricstreamfilter.html
Namespace string ` json:"Namespace" `
MetricNames [ ] string ` json:"MetricNames,omitempty" `
}
func ( amc * AWSMetricsCollectionStrategy ) AddServiceStrategy (
svcStrategy * AWSMetricsCollectionStrategy ,
) error {
if svcStrategy == nil {
return nil
}
amc . CloudwatchMetricsStreamFilters = append (
amc . CloudwatchMetricsStreamFilters ,
svcStrategy . CloudwatchMetricsStreamFilters ... ,
)
return nil
}
type AWSLogsCollectionStrategy struct {
CloudwatchLogsSubscriptions [ ] CloudwatchLogsSubscriptionConfig ` json:"cloudwatch_logs_subscriptions" `
}
type CloudwatchLogsSubscriptionConfig struct {
// subscribe to all logs groups with specified prefix.
// eg: `/aws/rds/`
LogGroupNamePrefix string ` json:"log_group_name_prefix" `
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
// "" implies no filtering is required.
FilterPattern string ` json:"filter_pattern" `
}
func ( alc * AWSLogsCollectionStrategy ) AddServiceStrategy (
svcStrategy * AWSLogsCollectionStrategy ,
) error {
if svcStrategy == nil {
return nil
}
alc . CloudwatchLogsSubscriptions = append (
alc . CloudwatchLogsSubscriptions ,
svcStrategy . CloudwatchLogsSubscriptions ... ,
)
return nil
}