Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (r ReceiverOTLP) Pipelines(ctx context.Context) ([]otel.ReceiverPipeline, e

receiverPipelineType, metricsRDM, metricsProcessors := r.metricsProcessors(ctx)

return []otel.ReceiverPipeline{{
return []otel.ReceiverPipeline{confgenerator.ConvertToOtlpExporter(otel.ReceiverPipeline{
ExporterTypes: map[string]otel.ExporterType{
"metrics": receiverPipelineType,
"traces": otel.OTel,
Expand All @@ -163,7 +163,7 @@ func (r ReceiverOTLP) Pipelines(ctx context.Context) ([]otel.ReceiverPipeline, e
"traces": otel.SetIfMissing,
"logs": otel.SetIfMissing,
},
}}, nil
}, ctx, false, false)}, nil
}

func init() {
Expand Down
63 changes: 45 additions & 18 deletions confgenerator/confgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,32 @@ func ConvertToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context,
if !expOtlpExporter {
return pipeline
}
_, err := pipeline.ExporterTypes["metrics"]
if !err {
return pipeline
}
pipeline.ExporterTypes["metrics"] = otel.OTLP
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.GCPProjectID(resource.ProjectName()))
if isSystem {
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveInstrumentationLibraryLabelsAttributes())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveServiceAttributes())
if _, ok := pipeline.ExporterTypes["metrics"]; ok {
pipeline.ExporterTypes["metrics"] = otel.OTLP
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.GCPProjectID(resource.ProjectName()))
if isSystem {
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveInstrumentationLibraryLabelsAttributes())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveServiceAttributes())
}
// The OTLP exporter doesn't batch by default like the googlecloud.* exporters. We need this to avoid the API point limits.
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.Batch())
if isPrometheus {
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricUnknownCounter())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricStartTime())
}
}

// The OTLP exporter doesn't batch by default like the googlecloud.* exporters. We need this to avoid the API point limits.
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.Batch())
if isPrometheus {
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricUnknownCounter())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricStartTime())
if _, ok := pipeline.ExporterTypes["logs"]; ok {
pipeline.ExporterTypes["logs"] = otel.OTLPStagingUTR
pipeline.Processors["logs"] = append(pipeline.Processors["logs"], otel.GCPProjectID(resource.ProjectName()))
pipeline.Processors["logs"] = append(pipeline.Processors["logs"], otel.Batch())
pipeline.Processors["logs"] = append(pipeline.Processors["logs"], otel.DisableOtlpRoundTrip())
pipeline.Processors["logs"] = append(pipeline.Processors["logs"], otel.InstrumentationScope())
pipeline.Processors["logs"] = append(pipeline.Processors["logs"], otel.CopyServiceResourceLabels())
pipeline.Processors["logs"] = append(pipeline.Processors["logs"], otel.ConvertSeverityTextToLowercase())
pipeline.Processors["logs"] = append(pipeline.Processors["logs"], otel.AddResourceType())
}

return pipeline
}

Expand All @@ -110,6 +119,23 @@ func otlpExporter(userAgent string) otel.Component {
}
}

// This will merge with the otlp exporter above once the prod UTR logging endpoint is ready.
func otlpExporterUTRLoggingStaging(userAgent string) otel.Component {
return otel.Component{
Type: "otlphttp",
Config: map[string]interface{}{
"endpoint": "https://test-us-central2-telemetry.sandbox.googleapis.com",
"auth": map[string]interface{}{
"authenticator": "googleclientauth",
},
"headers": map[string]string{
"User-Agent": userAgent,
},
"encoding": "json",
},
}
}

func googleManagedPrometheusExporter(userAgent string) otel.Component {
return otel.Component{
Type: "googlemanagedprometheus",
Expand Down Expand Up @@ -165,10 +191,11 @@ func (uc *UnifiedConfig) GenerateOtelConfig(ctx context.Context, outDir string)
Pipelines: pipelines,
Extensions: extensions,
Exporters: map[otel.ExporterType]otel.Component{
otel.System: googleCloudExporter(userAgent, false, false),
otel.OTel: googleCloudExporter(userAgent, true, true),
otel.GMP: googleManagedPrometheusExporter(userAgent),
otel.OTLP: otlpExporter(userAgent),
otel.System: googleCloudExporter(userAgent, false, false),
otel.OTel: googleCloudExporter(userAgent, true, true),
otel.GMP: googleManagedPrometheusExporter(userAgent),
otel.OTLP: otlpExporter(userAgent),
otel.OTLPStagingUTR: otlpExporterUTRLoggingStaging(userAgent),
},
}.Generate(ctx)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions confgenerator/logging_receivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (r LoggingReceiverFilesMixin) Pipelines(ctx context.Context) ([]otel.Receiv
})
}
receiver_config["operators"] = operators
return []otel.ReceiverPipeline{{
return []otel.ReceiverPipeline{ConvertToOtlpExporter(otel.ReceiverPipeline{
Receiver: otel.Component{
Type: "filelog",
Config: receiver_config,
Expand All @@ -243,7 +243,7 @@ func (r LoggingReceiverFilesMixin) Pipelines(ctx context.Context) ([]otel.Receiv
ExporterTypes: map[string]otel.ExporterType{
"logs": otel.OTel,
},
}}, nil
}, ctx, false, false)}, nil
}

func (r LoggingReceiverFilesMixin) MergeInternalLoggingProcessor(p InternalLoggingProcessor) (InternalLoggingReceiver, InternalLoggingProcessor) {
Expand Down Expand Up @@ -356,7 +356,7 @@ func (r LoggingReceiverSyslog) Pipelines(ctx context.Context) ([]otel.ReceiverPi
"protocol": "rfc5424",
}

return []otel.ReceiverPipeline{{
return []otel.ReceiverPipeline{ConvertToOtlpExporter(otel.ReceiverPipeline{
Receiver: otel.Component{
Type: "syslog",
Config: config,
Expand All @@ -368,7 +368,7 @@ func (r LoggingReceiverSyslog) Pipelines(ctx context.Context) ([]otel.ReceiverPi
ExporterTypes: map[string]otel.ExporterType{
"logs": otel.OTel,
},
}}, nil
}, ctx, false, false)}, nil
}

func init() {
Expand Down Expand Up @@ -1001,7 +1001,7 @@ func (r LoggingReceiverSystemd) Pipelines(ctx context.Context) ([]otel.ReceiverP
return nil, err
}

return []otel.ReceiverPipeline{{
return []otel.ReceiverPipeline{ConvertToOtlpExporter(otel.ReceiverPipeline{
Receiver: otel.Component{
Type: "journald",
Config: receiver_config,
Expand All @@ -1013,7 +1013,7 @@ func (r LoggingReceiverSystemd) Pipelines(ctx context.Context) ([]otel.ReceiverP
ExporterTypes: map[string]otel.ExporterType{
"logs": otel.OTel,
},
}}, nil
}, ctx, false, false)}, nil
}

func init() {
Expand Down
3 changes: 3 additions & 0 deletions confgenerator/otel/modular.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
System
GMP
OTLP
OTLPStagingUTR
)
const (
Override ResourceDetectionMode = iota
Expand All @@ -53,6 +54,8 @@ func (t ExporterType) Name() string {
return "otel"
} else if t == OTLP {
return "otlp"
} else if t == OTLPStagingUTR {
return "otlp-utr-logging"
} else {
panic("unknown ExporterType")
}
Expand Down
4 changes: 4 additions & 0 deletions confgenerator/otel/ottl/ottl.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ func IsNotNil(a Value) Value {
return valuef(`%s != nil`, a)
}

func IsNotEmptyString(a Value) Value {
return valuef(`%s != ""`, a)
}

// ExtractCountMetric creates a new metric based on the count value of a Histogram metric
func ExtractCountMetric(monotonic bool, metricName string) Statements {
monotonicStr := "false"
Expand Down
46 changes: 46 additions & 0 deletions confgenerator/otel/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,19 @@ func GCPProjectID(projectID string) Component {
)
}

// temp processor, will delete when UTR logging recognizes cloud.platform resource attribute
func AddResourceType() Component {
return ResourceTransform(
map[string]string{"gcp.resource_type": "gce_instance"}, false,
)
}

func DisableOtlpRoundTrip() Component {
return ResourceTransform(
map[string]string{"gcp.internal.omit_otlp": "true"}, false,
)
}

// MetricUnknownCounter is necessary to handle prometheus unknown type metrics
// go/ops-agent-otlp-migration
func MetricUnknownCounter() Component {
Expand All @@ -689,6 +702,39 @@ func MetricUnknownCounter() Component {
})
}

func InstrumentationScope() Component {
return Transform("log", "log", ottl.NewStatements(
ottl.LValue{"attributes", "instrumentation_source"}.SetIf(ottl.RValue("instrumentation_scope.name"), ottl.IsNotEmptyString(ottl.RValue("instrumentation_scope.name"))),
ottl.LValue{"attributes", "instrumentation_version"}.SetIf(ottl.RValue("instrumentation_scope.version"), ottl.IsNotEmptyString(ottl.RValue("instrumentation_scope.version"))),
))
}

func FlattenSourceLocation() Component {
return Transform("log", "log", ottl.NewStatements(
ottl.LValue{"attributes", "code.file.path"}.SetIf(ottl.RValue(`attributes["gcp.source_location"]["file"]`), ottl.IsNotNil(ottl.RValue(`attributes["gcp.source_location"]["file"]`))),
ottl.LValue{"attributes", "code.function.name"}.SetIf(ottl.RValue(`attributes["gcp.source_location"]["func"]`), ottl.IsNotNil(ottl.RValue(`attributes["gcp.source_location"]["func"]`))),
ottl.LValue{"attributes", "code.line.number"}.SetIf(ottl.RValue(`attributes["gcp.source_location"]["line"]`), ottl.IsNotNil(ottl.RValue(`attributes["gcp.source_location"]["line"]`))),
ottl.LValue{"attributes", "gcp.source_location"}.Delete(),
))
}

// This processor copies the service.* attributes from the resource to the log attributes, if they exist.
func CopyServiceResourceLabels() Component {
return Transform("log", "log", ottl.NewStatements(
ottl.LValue{"attributes", "service.name"}.SetIf(ottl.RValue(`resource.attributes["service.name"]`), ottl.IsNotNil(ottl.RValue(`resource.attributes["service.name"]`))),
ottl.LValue{"attributes", "service.namespace"}.SetIf(ottl.RValue(`resource.attributes["service.namespace"]`), ottl.IsNotNil(ottl.RValue(`resource.attributes["service.namespace"]`))),
ottl.LValue{"attributes", "service.instance.id"}.SetIf(ottl.RValue(`resource.attributes["service.instance.id"]`), ottl.IsNotNil(ottl.RValue(`resource.attributes["service.instance.id"]`))),
))
}

// A temp processor, will delete when UTR logging supports case-insensitive severity text parsing.
func ConvertSeverityTextToLowercase() Component {
return Transform("log", "log", []ottl.Statement{
`set(severity_text, ToLowerCase(severity_text)) where severity_text != nil`,
})

}

func Batch() Component {
return Component{
Type: "batch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ exporters:
service_resource_labels: true
skip_create_descriptor: true
user_agent: Google-Cloud-Ops-Agent-Metrics/latest (BuildDistro=build_distro;Platform=linux;ShortName=linux_platform;ShortVersion=linux_platform_version)
googlemanagedprometheus:
metric:
add_metric_suffixes: false
user_agent: Google-Cloud-Ops-Agent-Metrics/latest (BuildDistro=build_distro;Platform=linux;ShortName=linux_platform;ShortVersion=linux_platform_version)
otlphttp/otlp:
auth:
authenticator: googleclientauth
Expand All @@ -37,6 +33,9 @@ processors:
batch/hostmetrics_6:
send_batch_max_size: 200
send_batch_size: 200
batch/otlp_4:
send_batch_max_size: 200
send_batch_size: 200
cumulativetodelta/loggingmetrics_4:
include:
match_type: strict
Expand Down Expand Up @@ -618,6 +617,11 @@ processors:
- action: insert
key: gcp.project_id
value: test-project
resource/otlp_3:
attributes:
- action: insert
key: gcp.project_id
value: test-project
resourcedetection/_global_0:
detectors:
- gcp
Expand Down Expand Up @@ -834,11 +838,13 @@ service:
- prometheus/agent_prometheus
metrics/otlp_otlp:
exporters:
- googlemanagedprometheus
- otlphttp/otlp
processors:
- resourcedetection/otlp_0
- transform/otlp_1
- groupbyattrs/otlp_2
- resource/otlp_3
- batch/otlp_4
receivers:
- otlp/otlp
traces/traces_otlp_otlp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ exporters:
service_resource_labels: true
skip_create_descriptor: true
user_agent: Google-Cloud-Ops-Agent-Metrics/latest (BuildDistro=build_distro;Platform=linux;ShortName=linux_platform;ShortVersion=linux_platform_version)
googlemanagedprometheus:
metric:
add_metric_suffixes: false
user_agent: Google-Cloud-Ops-Agent-Metrics/latest (BuildDistro=build_distro;Platform=linux;ShortName=linux_platform;ShortVersion=linux_platform_version)
otlphttp/otlp:
auth:
authenticator: googleclientauth
Expand All @@ -34,6 +30,9 @@ processors:
batch/hostmetrics_6:
send_batch_max_size: 200
send_batch_size: 200
batch/otlp_4:
send_batch_max_size: 200
send_batch_size: 200
cumulativetodelta/loggingmetrics_4:
include:
match_type: strict
Expand Down Expand Up @@ -581,6 +580,11 @@ processors:
- action: insert
key: gcp.project_id
value: test-project
resource/otlp_3:
attributes:
- action: insert
key: gcp.project_id
value: test-project
resourcedetection/_global_0:
detectors:
- gcp
Expand Down Expand Up @@ -767,11 +771,13 @@ service:
- prometheus/agent_prometheus
metrics/otlp_otlp:
exporters:
- googlemanagedprometheus
- otlphttp/otlp
processors:
- resourcedetection/otlp_0
- transform/otlp_1
- groupbyattrs/otlp_2
- resource/otlp_3
- batch/otlp_4
receivers:
- otlp/otlp
traces/traces_otlp_otlp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ exporters:
service_resource_labels: true
skip_create_descriptor: true
user_agent: Google-Cloud-Ops-Agent-Metrics/latest (BuildDistro=build_distro;Platform=windows;ShortName=win_platform;ShortVersion=win_platform_version)
googlemanagedprometheus:
metric:
add_metric_suffixes: false
user_agent: Google-Cloud-Ops-Agent-Metrics/latest (BuildDistro=build_distro;Platform=windows;ShortName=win_platform;ShortVersion=win_platform_version)
otlphttp/otlp:
auth:
authenticator: googleclientauth
Expand All @@ -40,6 +36,9 @@ processors:
batch/mssql_5:
send_batch_max_size: 200
send_batch_size: 200
batch/otlp_4:
send_batch_max_size: 200
send_batch_size: 200
casttosum/iis_1:
metrics:
- agent.googleapis.com/iis/network/transferred_bytes_count
Expand Down Expand Up @@ -663,6 +662,11 @@ processors:
- action: insert
key: gcp.project_id
value: test-project
resource/otlp_3:
attributes:
- action: insert
key: gcp.project_id
value: test-project
resourcedetection/_global_0:
detectors:
- gcp
Expand Down Expand Up @@ -956,11 +960,13 @@ service:
- prometheus/agent_prometheus
metrics/otlp_otlp:
exporters:
- googlemanagedprometheus
- otlphttp/otlp
processors:
- resourcedetection/otlp_0
- transform/otlp_1
- groupbyattrs/otlp_2
- resource/otlp_3
- batch/otlp_4
receivers:
- otlp/otlp
traces/traces_otlp_otlp:
Expand Down
Loading
Loading