Skip to content

Commit

Permalink
generate + fix some things
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
codeboten committed May 21, 2024
1 parent 73790bb commit ec08ca0
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 8 deletions.
55 changes: 55 additions & 0 deletions service/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# service

## Internal Telemetry

The following telemetry is emitted by this component.

### process_cpu_seconds

Total CPU user and system time in seconds

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| s | Sum | Double | true |

### process_memory_rss

Total physical memory (resident set size)

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| By | Gauge | Int |

### process_runtime_heap_alloc_bytes

Bytes of allocated heap objects (see 'go doc runtime.MemStats.HeapAlloc')

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| By | Gauge | Int |

### process_runtime_total_alloc_bytes

Cumulative bytes allocated for heap objects (see 'go doc runtime.MemStats.TotalAlloc')

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| By | Sum | Int | true |

### process_runtime_total_sys_memory_bytes

Total bytes of memory obtained from the OS (see 'go doc runtime.MemStats.Sys')

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| By | Gauge | Int |

### process_uptime

Uptime of the process

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| s | Sum | Double | true |
13 changes: 13 additions & 0 deletions service/generated_package_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions service/internal/metadata/generated_telemetry_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions service/internal/proctelemetry/process_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/service/internal/metadata"
"go.opentelemetry.io/collector/service/internal/servicetelemetry"
)

// processMetrics is a struct that contains views related to process metrics (cpu, mem, etc)
Expand Down Expand Up @@ -53,7 +54,7 @@ func WithHostProc(hostProc string) RegisterOption {

// RegisterProcessMetrics creates a new set of processMetrics (mem, cpu) that can be used to measure
// basic information about this process.
func RegisterProcessMetrics(cfg component.TelemetrySettings, ballastSizeBytes uint64, opts ...RegisterOption) error {
func RegisterProcessMetrics(cfg servicetelemetry.TelemetrySettings, ballastSizeBytes uint64, opts ...RegisterOption) error {
set := registerOption{}
for _, opt := range opts {
opt.apply(&set)
Expand All @@ -75,7 +76,7 @@ func RegisterProcessMetrics(cfg component.TelemetrySettings, ballastSizeBytes ui
return err
}

_, err = metadata.NewTelemetryBuilder(cfg,
_, err = metadata.NewTelemetryBuilder(cfg.ToComponentTelemetrySettings(&component.InstanceID{}),
metadata.WithProcessUptimeCallback(pm.updateProcessUptime),
metadata.WithProcessRuntimeHeapAllocBytesCallback(pm.updateAllocMem),
metadata.WithProcessRuntimeTotalAllocBytesCallback(pm.updateTotalAllocMem),
Expand Down
9 changes: 4 additions & 5 deletions service/internal/proctelemetry/process_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import (
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/service/internal/servicetelemetry"
)

type testTelemetry struct {
component.TelemetrySettings
servicetelemetry.TelemetrySettings
promHandler http.Handler
meterProvider *sdkmetric.MeterProvider
}
Expand All @@ -42,7 +41,7 @@ var expectedMetrics = []string{

func setupTelemetry(t *testing.T) testTelemetry {
settings := testTelemetry{
TelemetrySettings: componenttest.NewNopTelemetrySettings(),
TelemetrySettings: servicetelemetry.NewNopTelemetrySettings(),
}
settings.TelemetrySettings.MetricsLevel = configtelemetry.LevelNormal

Expand Down Expand Up @@ -79,7 +78,7 @@ func fetchPrometheusMetrics(handler http.Handler) (map[string]*io_prometheus_cli
func TestProcessTelemetry(t *testing.T) {
tel := setupTelemetry(t)

require.NoError(t, RegisterProcessMetrics(tel.MeterProvider, 0))
require.NoError(t, RegisterProcessMetrics(tel.TelemetrySettings, 0))

mp, err := fetchPrometheusMetrics(tel.promHandler)
require.NoError(t, err)
Expand Down
8 changes: 8 additions & 0 deletions service/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ status:
development: [traces, metrics, logs]
distributions: [core, contrib]

tests:
goleak:
ignore:
top:
# See https://github.com/census-instrumentation/opencensus-go/issues/1191 for more information.
- "go.opencensus.io/stats/view.(*worker).start"
- "go.opentelemetry.io/collector/service/internal/proctelemetry.InitPrometheusServer.func1"

telemetry:
metrics:
process_uptime:
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (srv *Service) initExtensionsAndPipeline(ctx context.Context, set Settings,

if cfg.Telemetry.Metrics.Level != configtelemetry.LevelNone && cfg.Telemetry.Metrics.Address != "" {
// The process telemetry initialization requires the ballast size, which is available after the extensions are initialized.
if err = proctelemetry.RegisterProcessMetrics(srv.telemetrySettings.MeterProvider, getBallastSize(srv.host)); err != nil {
if err = proctelemetry.RegisterProcessMetrics(srv.telemetrySettings, getBallastSize(srv.host)); err != nil {
return fmt.Errorf("failed to register process metrics: %w", err)
}
}
Expand Down

0 comments on commit ec08ca0

Please sign in to comment.