func()

in apps/postgresql.go [48:105]


func (r MetricsReceiverPostgresql) Pipelines(_ context.Context) ([]otel.ReceiverPipeline, error) {
	transport := "tcp"
	if r.Endpoint == "" {
		transport = "unix"
		r.Endpoint = defaultPostgresqlUnixEndpoint
	} else if strings.HasPrefix(r.Endpoint, "/") {
		transport = "unix"
		endpointParts := strings.Split(r.Endpoint, ".")
		r.Endpoint = strings.TrimLeft(endpointParts[0], "/") + ":" + endpointParts[len(endpointParts)-1]
	}

	cfg := map[string]interface{}{
		"collection_interval": r.CollectionIntervalString(),
		"endpoint":            r.Endpoint,
		"username":            r.Username,
		"password":            r.Password.SecretValue(),
		"transport":           transport,
		"metrics": map[string]any{
			"postgresql.wal.delay": map[string]any{
				"enabled": true,
			},
			"postgresql.wal.lag": map[string]any{
				"enabled": false,
			},
		},
	}

	if transport == "tcp" {
		cfg["tls"] = r.TLSConfig(true)
	}

	return []otel.ReceiverPipeline{{
		Receiver: otel.Component{
			Type:   "postgresql",
			Config: cfg,
		},
		Processors: map[string][]otel.Component{"metrics": {
			otel.NormalizeSums(),
			otel.TransformationMetrics(
				otel.FlattenResourceAttribute("postgresql.database.name", "database"),
				otel.FlattenResourceAttribute("postgresql.table.name", "table"),
				otel.FlattenResourceAttribute("postgresql.index.name", "index"),
				// As of version 0.89, the postgresql receiver supports a double-precision wal.lag metric replacement
				// the following two transforms convert it back to integer-precision wal.lag for backwards compatibility.
				// The two metrics are mutually exclusive so we do not need to worry about overwriting or removing the original wal.lag.
				otel.ConvertFloatToInt("postgresql.wal.delay"),
				otel.SetName("postgresql.wal.delay", "postgresql.wal.lag"),
			),
			otel.MetricsTransform(
				otel.UpdateMetric("postgresql.bgwriter.duration",
					otel.ToggleScalarDataType,
				),
				otel.AddPrefix("workload.googleapis.com"),
			),
			otel.ModifyInstrumentationScope(r.Type(), "1.0"),
		}},
	}}, nil
}