Skip to content

Commit

Permalink
Merge pull request #58 from siemens/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
thediveo authored Jul 24, 2024
2 parents 3d8c3d1 + e8951c5 commit 7c2ae8e
Show file tree
Hide file tree
Showing 33 changed files with 5,534 additions and 5,482 deletions.
26 changes: 25 additions & 1 deletion api/v1/netns.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func (n *networkNamespace) marshal(allnetns *networkNamespaces) ([]byte, error)
Status: status,
Type: typ,
TypeText: titler.String(typ),
Affinity: tenant.Process.Affinity,
Policy: tenant.Process.Policy,
Priority: tenant.Process.Policy,
Nice: tenant.Process.Nice,
})
} else {
// It's a stand-alone process
Expand All @@ -217,11 +221,15 @@ func (n *networkNamespace) marshal(allnetns *networkNamespaces) ([]byte, error)
Status: status,
Type: "proc",
TypeText: "Process",
Affinity: tenant.Process.Affinity,
Policy: tenant.Process.Policy,
Priority: tenant.Process.Policy,
Nice: tenant.Process.Nice,
})
}
}
} else {
// special case: either stand-alone processes nor containers, so
// special case: neither stand-alone processes nor containers, so
// Ghostwire v1 emits a bind-mount "container" instead.
cntrs = append(cntrs, container{
ID: "bmnt-" + strconv.FormatUint(n.ID().Ino, 10),
Expand Down Expand Up @@ -285,6 +293,22 @@ type container struct {
Status string `json:"status"`
Type string `json:"type"`
TypeText string `json:"type-text"`
Affinity model.CPUList `json:"affinity,omitempty"`
Policy int `json:"policy,omitempty"`
// priority value is considered by the following schedulers:
// - SCHED_FIFO: prio 1..99.
// - SCHED_RR: prio 1..99.
// - SCHED_NORMAL (=SCHED_OTHER): not used/prio is 0.
// - SCHED_IDLE: not used/prio is 0.
// - SCHED_BATCH: not used/prio is 0.
// - SCHED_DEADLINE: doesn't use prio.
Priority int `json:"priority,omitempty"`
// nice value in the range +19..-20 (very nice ... less nice) is considered
// by the following schedulers:
// - SCHED_NORMAL (=SCHED_OTHER): nice is taken into account.
// - SCHED_BATCH: nice is taken into account.
// - SCHED_IDLE: nice is ignored (basically below a nic of +19).
Nice int `json:"nice,omitempty"`
}

type dns struct {
Expand Down
10 changes: 5 additions & 5 deletions deployments/gostwire/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# Nota bene: not all existing value combinations with respect to Alpine and Node
# versions might work, so you'll need to check Docker hub for the available base
# image versions.
ARG ALPINE_VERSION=3.19
ARG ALPINE_PATCH=1
ARG GO_VERSION=1.22.2
ARG NODE_VERSION=21
ARG ALPINE_VERSION=3.20
ARG ALPINE_PATCH=2
ARG GO_VERSION=1.22.5
ARG NODE_VERSION=20

# Go build settings
ARG LDFLAGS="-s -w -extldflags=-static"
Expand Down Expand Up @@ -166,7 +166,7 @@ RUN setcap "cap_sys_admin,cap_sys_chroot,cap_sys_ptrace,cap_dac_read_search,cap_
#
# In the final stage we now "only" need to install the gostwire service binary
# and its web ui application into the final image.
FROM alpine:${ALPINE_VERSION}.${ALPINE_PATCH} as final
FROM alpine:${ALPINE_VERSION}.${ALPINE_PATCH} AS final
LABEL maintainer="Harald Albrecht <[email protected]>"
ARG ALPINE_VERSION
ARG GOLANG_VERSION
Expand Down
594 changes: 297 additions & 297 deletions docs/api/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions internal/discover/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Discover(ctx context.Context, cizer containerizer.Containerizer, labels map
lxknsdiscover.WithContainerizer(cizer),
lxknsdiscover.WithPIDMapper(),
lxknsdiscover.WithLabels(labels),
lxknsdiscover.WithAffinityAndScheduling(),
)
// Second phase: create the Gostwire-specific information model based on the
// lxkns discovery and augment the model with additional network-related
Expand Down
1 change: 1 addition & 0 deletions metadata/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package all

import (
_ "github.com/siemens/ghostwire/v2/metadata/cpus"
_ "github.com/siemens/ghostwire/v2/metadata/engines"
_ "github.com/siemens/ghostwire/v2/metadata/host"
_ "github.com/siemens/ghostwire/v2/metadata/iecore"
Expand Down
84 changes: 84 additions & 0 deletions metadata/cpus/cpus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// (c) Siemens AG 2024
//
// SPDX-License-Identifier: MIT

package cpus

import (
"os"
"strconv"
"strings"

"github.com/siemens/ghostwire/v2/metadata"
"github.com/thediveo/go-plugger/v3"
"github.com/thediveo/lxkns/log"
"github.com/thediveo/lxkns/model"

gostwire "github.com/siemens/ghostwire/v2"
)

func init() {
plugger.Group[metadata.Metadata]().Register(
Metadata, plugger.WithPlugin("cpus"))
}

// Metadata returns metadata describing certain aspects of the host the
// discovery was run on, such as its host name, OS version, ...
func Metadata(r gostwire.DiscoveryResult) map[string]interface{} {
onlinecpus, err := os.ReadFile("/sys/devices/system/cpu/online")
if err != nil {
log.Errorf("cannot retrieve list of online cpus, reason: %s", err.Error())
return nil
}
cpulist := parseCPUList(strings.TrimSuffix(string(onlinecpus), "\n"))
if cpulist == nil {
log.Errorf("malformed /sys/devices/system/cpu/online")
return nil
}
return map[string]interface{}{
"cpus": cpulist,
}
}

// parseCPUList parses the textual representation of a CPU list in form of
// comma-separated CPU ranges, returning the CPUList if successful; otherwise,
// it returns nil.
func parseCPUList(cpus string) (list model.CPUList) {
for cpus != "" {
cpurange := cpus
sepIdx := strings.Index(cpus, ",")
if sepIdx < 0 {
// final range, so there won't be any further ranges
cpus = ""
} else {
// intermediate range...
cpurange = cpus[:sepIdx]
cpus = cpus[sepIdx+1:]
// ...there needs to be something following, so no hanging commas.
if cpus == "" {
return nil
}
}
dashIdx := strings.Index(cpurange, "-")
if dashIdx < 0 {
// single CPU number
cpuno, err := strconv.ParseUint(cpurange, 10, 32)
if err != nil {
return nil
}
list = append(list, [2]uint{uint(cpuno), uint(cpuno)})
continue
}
// CPU number range
fromcpu, err := strconv.ParseUint(cpurange[:dashIdx], 10, 32)
if err != nil {
return nil
}
tocpu, err := strconv.ParseUint(cpurange[dashIdx+1:], 10, 32)
if err != nil {
return nil
}
list = append(list, [2]uint{uint(fromcpu), uint(tocpu)})
}
return list
}
31 changes: 31 additions & 0 deletions metadata/cpus/cpus_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// (c) Siemens AG 2024
//
// SPDX-License-Identifier: MIT

package cpus

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/thediveo/lxkns/model"
)

var _ = Describe("CPUs online", func() {

DescribeTable("parsing CPU ranges",
func(cpus string, expected model.CPUList) {
Expect(parseCPUList(cpus)).To(Equal(expected))
},
Entry(nil, "", nil),
Entry(nil, "abc", nil),
Entry(nil, "42,", nil),
Entry(nil, "42-", nil),
Entry(nil, "42-abc", nil),
Entry(nil, "def-42", nil),
Entry(nil, "42", model.CPUList{{42, 42}}),
Entry(nil, "42,43", model.CPUList{{42, 42}, {43, 43}}),
Entry(nil, "1-42", model.CPUList{{1, 42}}),
Entry(nil, "1-42,555,666-667", model.CPUList{{1, 42}, {555, 555}, {666, 667}}),
)

})
13 changes: 13 additions & 0 deletions metadata/cpus/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Package cpus provides a metadata plugin returning information about the CPUs in
the system that are currently “online”.
The information about the CPUs being online is taken from
“/sys/devices/system/cpu/online” (a list of CPU ranges in textual format,
separated by commas).
The (JSON) metadata is structured (inside “metadata”) as follows:
- “cpus”: slice of two-elements slice ranges.
*/
package cpus
17 changes: 17 additions & 0 deletions metadata/cpus/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// (c) Siemens AG 2024
//
// SPDX-License-Identifier: MIT

package cpus

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestMetadataCPUs(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "ghostwire/metadata/cpus package")
}
2 changes: 1 addition & 1 deletion metadata/host/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Package host implements a metadata plugin returning information about the host
system the discovery was run on.
The (JSON) metadata is structured (inside "metadata") as follows:
The (JSON) metadata is structured (inside metadata) as follows:
- “hostname”: string
*/
Expand Down
1 change: 1 addition & 0 deletions metadata/package_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// (c) Siemens AG 2023
//
// SPDX-License-Identifier: MIT

package metadata

import (
Expand Down
Loading

0 comments on commit 7c2ae8e

Please sign in to comment.