container: support hostprocess containers and expose kubernetes labels (#1911)

This commit is contained in:
Jan-Otto Kröpke
2025-05-18 09:39:52 +02:00
committed by GitHub
parent 6b87441729
commit 898e16bcb1
43 changed files with 1800 additions and 296 deletions

View File

@@ -0,0 +1,53 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
package kernel32
import (
"unsafe"
"golang.org/x/sys/windows"
)
const (
// JobObjectQuery is required to retrieve certain information about a job object,
// such as attributes and accounting information (see QueryInformationJobObject and IsProcessInJob).
// https://learn.microsoft.com/en-us/windows/win32/procthread/job-object-security-and-access-rights
JobObjectQuery = 0x0004
)
func OpenJobObject(name string) (windows.Handle, error) {
handle, _, err := procOpenJobObject.Call(JobObjectQuery, 0, uintptr(unsafe.Pointer(&name)))
if handle == 0 {
return 0, err
}
return windows.Handle(handle), nil
}
func IsProcessInJob(process windows.Handle, job windows.Handle, result *bool) error {
ret, _, err := procIsProcessInJob.Call(
uintptr(process),
uintptr(job),
uintptr(unsafe.Pointer(&result)),
)
if ret == 0 {
return err
}
return nil
}

View File

@@ -30,6 +30,8 @@ var (
procGetDynamicTimeZoneInformationSys = modkernel32.NewProc("GetDynamicTimeZoneInformation")
procKernelLocalFileTimeToFileTime = modkernel32.NewProc("LocalFileTimeToFileTime")
procGetTickCount = modkernel32.NewProc("GetTickCount64")
procOpenJobObject = modkernel32.NewProc("OpenJobObjectW")
procIsProcessInJob = modkernel32.NewProc("IsProcessInJob")
)
// SYSTEMTIME contains a date and time.

View File

@@ -0,0 +1,75 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
package kernel32
import "unsafe"
type JobObjectBasicAccountingInformation struct {
TotalUserTime uint64
TotalKernelTime uint64
ThisPeriodTotalUserTime uint64
ThisPeriodTotalKernelTime uint64
TotalPageFaultCount uint32
TotalProcesses uint32
ActiveProcesses uint32
TotalTerminatedProcesses uint32
}
type IOCounters struct {
ReadOperationCount uint64
WriteOperationCount uint64
OtherOperationCount uint64
ReadTransferCount uint64
WriteTransferCount uint64
OtherTransferCount uint64
}
type JobObjectExtendedLimitInformation struct {
BasicInfo JobObjectBasicAccountingInformation
IoInfo IOCounters
ProcessMemoryLimit uint64
JobMemoryLimit uint64
PeakProcessMemoryUsed uint64
PeakJobMemoryUsed uint64
}
type JobObjectBasicProcessIDList struct {
NumberOfAssignedProcesses uint32
NumberOfProcessIdsInList uint32
ProcessIdList [1]uintptr
}
// PIDs returns all the process Ids in the job object.
func (p *JobObjectBasicProcessIDList) PIDs() []uint32 {
return unsafe.Slice((*uint32)(unsafe.Pointer(&p.ProcessIdList[0])), int(p.NumberOfProcessIdsInList))
}
type PROCESS_VM_COUNTERS struct {
PeakVirtualSize uintptr
VirtualSize uintptr
PageFaultCount uint32
PeakWorkingSetSize uintptr
WorkingSetSize uintptr
QuotaPeakPagedPoolUsage uintptr
QuotaPagedPoolUsage uintptr
QuotaPeakNonPagedPoolUsage uintptr
QuotaNonPagedPoolUsage uintptr
PagefileUsage uintptr
PeakPagefileUsage uintptr
PrivateWorkingSetSize uintptr
}