Skip to content

Add a null check in thread sampling instrumentation #15051

@vrajat

Description

@vrajat

Issues like #15045 are caused because some query execution paths are not instrumented to capture thread usage. When instrumentation is turned on NPE is caused. Since it is not possible to guarantee that all execution paths are covered, add a null check before sampling for resource usage. Bonus points if the data has a marker that a code path was not instrumented.

Specifically, change

      if (_isThreadMemorySamplingEnabled) {
        _threadLocalEntry.get()._currentThreadMemoryAllocationSampleBytes
            = getThreadResourceUsageProvider().getThreadAllocatedBytes();
      }

to

      if (_isThreadMemorySamplingEnabled && getThreadResourceUsageProvider() != null) {
        _threadLocalEntry.get()._currentThreadMemoryAllocationSampleBytes
            = getThreadResourceUsageProvider().getThreadAllocatedBytes();
      }

This will improve the confidence in the feature because queries will continue to work and not error out with NPE. The only possible concern is perf impact due to the extra check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions