Skip to content

fix: solaris build compatibility #45105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions filebeat/channel/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import (
"fmt"
"runtime"

Check failure on line 22 in filebeat/channel/runner_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

File is not properly formatted (goimports)
"strings"
"testing"
"time"

Expand Down Expand Up @@ -235,6 +237,12 @@
pipeline: "test"
index: "%{[fields.log_type]}-%{[agent.version]}-%{+yyyy.MM.dd}"
`
// illumos: this specific test requires add_kubernetes_metadata for side-effects
// in this test which trigger issues for the stubbed version provided for
// illumos (see prior comment about the side-effects being the purpose).
if runtime.GOOS == "illumos" {
configYAML = strings.ReplaceAll(configYAML, "\n - add_kubernetes_metadata: ~","")
}
cfg, err := conf.NewConfigWithYAML([]byte(configYAML), configYAML)
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build integration
//go:build (!aix && !solaris) && integration

Check failure on line 18 in libbeat/autodiscover/providers/docker/docker_integration_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

File is not properly formatted (goimports)

package docker

Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix && !solaris

package docker

import (
Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix && !solaris

package kubernetes

import (
Expand Down
112 changes: 112 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/kubernetes_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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 aix || solaris

package kubernetes

import (
"fmt"

"github.com/gofrs/uuid"

"github.com/elastic/beats/v7/libbeat/autodiscover"
"github.com/elastic/elastic-agent-autodiscover/bus"
"github.com/elastic/elastic-agent-autodiscover/kubernetes"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/keystore"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/mapstr"
)

func init() {
err := autodiscover.Registry.AddProvider("kubernetes", AutodiscoverBuilder)
if err != nil {
logp.Error(fmt.Errorf("could not add `hints` builder"))
}
}

// Eventer allows defining ways in which kubernetes resource events are observed and processed
type Eventer interface {
kubernetes.ResourceEventHandler
GenerateHints(event bus.Event) bus.Event
Start() error
Stop()
}

// EventManager allows defining ways in which kubernetes resource events are observed and processed
type EventManager interface {
GenerateHints(event bus.Event) bus.Event
Start()
Stop()
}

// Provider implements autodiscover provider for docker containers
type Provider struct {
logger *logp.Logger
}

// AutodiscoverBuilder builds and returns an autodiscover provider
func AutodiscoverBuilder(
beatName string,
bus bus.Bus,
uuid uuid.UUID,
c *config.C,
keystore keystore.Keystore,
) (autodiscover.Provider, error) {
logger := logp.NewLogger("autodiscover")

p := &Provider{
logger: logger,
}

return p, nil
}

// Start for Runner interface.
func (p *Provider) Start() {
}

// Stop signals the stop channel to force the watch loop routine to stop.
func (p *Provider) Stop() {
}

// String returns a description of kubernetes autodiscover provider.
func (p *Provider) String() string {
return "kubernetes"
}

func (p *Provider) publish(events []bus.Event) {
if len(events) == 0 {
return
}

}

func ShouldPut(event mapstr.M, field string, value interface{}, logger *logp.Logger) {
_, err := event.Put(field, value)
if err != nil {
logger.Debugf("Failed to put field '%s' with value '%s': %s", field, value, err)
}
}

func ShouldDelete(event mapstr.M, field string, logger *logp.Logger) {
err := event.Delete(field)
if err != nil {
logger.Debugf("Failed to delete field '%s': %s", field, err)
}
}
2 changes: 1 addition & 1 deletion libbeat/autodiscover/providers/kubernetes/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix
//go:build !aix && !solaris

package kubernetes

Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix && !solaris

package kubernetes

import (
Expand Down
2 changes: 1 addition & 1 deletion libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix
//go:build !aix && !solaris

package kubernetes

Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build ( !aix && !solaris )

Check failure on line 18 in libbeat/autodiscover/providers/kubernetes/pod_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

File is not properly formatted (goimports)

package kubernetes

import (
Expand Down
2 changes: 1 addition & 1 deletion libbeat/autodiscover/providers/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix
//go:build !aix && !solaris

package kubernetes

Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix && !solaris

package kubernetes

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

p, err := New(testConfig, logptest.NewTestingLogger(t, ""))
switch runtime.GOOS {
case "windows", "darwin", "linux":
case "windows", "darwin", "linux", "solaris":
assert.NoError(t, err)
default:
assert.IsType(t, types.ErrNotImplemented, err)
Expand Down Expand Up @@ -101,7 +101,7 @@

p, err := New(testConfig, logptest.NewTestingLogger(t, ""))
switch runtime.GOOS {
case "windows", "darwin", "linux":
case "windows", "darwin", "linux", "solaris":
assert.NoError(t, err)
default:
assert.IsType(t, types.ErrNotImplemented, err)
Expand Down Expand Up @@ -227,7 +227,7 @@

p, err := New(testConfig, logptest.NewTestingLogger(t, ""))
switch runtime.GOOS {
case "windows", "darwin", "linux":
case "windows", "darwin", "linux", "solaris":
assert.NoError(t, err)
default:
assert.IsType(t, types.ErrNotImplemented, err)
Expand Down Expand Up @@ -290,10 +290,10 @@

v, err := newEvent.GetValue("host")
assert.NoError(t, err)
assert.Equal(t, c.hostLengthLargerThanOne, len(v.(mapstr.M)) > 1)

Check failure on line 293 in libbeat/processors/add_host_metadata/add_host_metadata_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Error return value is not checked (errcheck)
assert.Equal(t, c.hostLengthEqualsToOne, len(v.(mapstr.M)) == 1)

Check failure on line 294 in libbeat/processors/add_host_metadata/add_host_metadata_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Error return value is not checked (errcheck)
if c.expectedHostFieldLength != -1 {
assert.Equal(t, c.expectedHostFieldLength, len(v.(mapstr.M)))

Check failure on line 296 in libbeat/processors/add_host_metadata/add_host_metadata_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Error return value is not checked (errcheck)
}
})
}
Expand All @@ -307,7 +307,7 @@

p, err := New(testConfig, logptest.NewTestingLogger(t, ""))
switch runtime.GOOS {
case "windows", "darwin", "linux":
case "windows", "darwin", "linux", "solaris":
assert.NoError(t, err)
default:
assert.IsType(t, types.ErrNotImplemented, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix && !solaris

package add_kubernetes_metadata

import (
Expand Down
2 changes: 2 additions & 0 deletions libbeat/tests/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !solaris

package compose

import (
Expand Down Expand Up @@ -173,7 +175,7 @@
return "", err
}
for {
if path == "/" {

Check failure on line 178 in libbeat/tests/compose/compose.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1006: could lift into loop condition (staticcheck)
break
}

Expand Down
2 changes: 2 additions & 0 deletions libbeat/tests/compose/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !solaris

package compose

import (
Expand Down Expand Up @@ -301,7 +303,7 @@
defer file.Close()

var pid int
fmt.Fscanf(file, "%d", &pid)

Check failure on line 306 in libbeat/tests/compose/project.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Error return value of `fmt.Fscanf` is not checked (errcheck)

return !processExists(pid)
}
Expand Down
2 changes: 2 additions & 0 deletions libbeat/tests/compose/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !solaris

package compose

import (
Expand Down Expand Up @@ -116,7 +118,7 @@
}

for _, info := range c.info.Ports {
if info.PublicPort != uint16(0) && (port == 0 || info.PrivatePort == uint16(port)) {

Check failure on line 121 in libbeat/tests/compose/wrapper.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

G115: integer overflow conversion int -> uint16 (gosec)
return net.JoinHostPort(ip, strconv.Itoa(int(info.PrivatePort)))
}
}
Expand All @@ -127,7 +129,7 @@
// test is run from the host network. Recommended when using docker machines.
func (c *wrapperContainer) exposedHost(port int) string {
for _, info := range c.info.Ports {
if info.PublicPort != uint16(0) && (port == 0 || info.PrivatePort == uint16(port)) {

Check failure on line 132 in libbeat/tests/compose/wrapper.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

G115: integer overflow conversion int -> uint16 (gosec)
return net.JoinHostPort("localhost", strconv.Itoa(int(info.PublicPort)))
}
}
Expand Down
2 changes: 2 additions & 0 deletions libbeat/tests/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

//go:build !solaris

package docker

import (
Expand Down
Loading