Skip to content

Commit

Permalink
fix: add support for solaris in libbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
gaige committed Sep 11, 2023
1 parent f4535a4 commit 81fe3bc
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 8 deletions.
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 ( linux || darwin || windows ) && integration

package docker

Expand Down
3 changes: 3 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,9 @@
// specific language governing permissions and limitations
// under the License.

//go:build ( linux || darwin || windows )
// +build linux darwin windows

package docker

import (
Expand Down
3 changes: 3 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,9 @@
// specific language governing permissions and limitations
// under the License.

//go:build linux || darwin || windows
// +build linux darwin windows

package kubernetes

import (
Expand Down
114 changes: 114 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/kubernetes_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// 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 )
// +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
3 changes: 3 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,9 @@
// specific language governing permissions and limitations
// under the License.

//go:build linux || darwin || windows
// +build linux darwin windows

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
3 changes: 3 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,9 @@
// specific language governing permissions and limitations
// under the License.

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

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
3 changes: 3 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,9 @@
// specific language governing permissions and limitations
// under the License.

//go:build ( linux || darwin || windows )
// +build linux darwin windows

package kubernetes

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestConfigDefault(t *testing.T) {

p, err := New(testConfig)
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 @@ -100,7 +100,7 @@ func TestConfigNetInfoDisabled(t *testing.T) {

p, err := New(testConfig)
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 @@ -226,7 +226,7 @@ func TestEventWithReplaceFieldsFalse(t *testing.T) {

p, err := New(testConfig)
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 @@ -306,7 +306,7 @@ func TestEventWithReplaceFieldsTrue(t *testing.T) {

p, err := New(testConfig)
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
3 changes: 3 additions & 0 deletions libbeat/processors/add_kubernetes_metadata/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.

//go:build linux || darwin || windows
// +build linux darwin windows

package add_kubernetes_metadata

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

//go:build !solaris
// +build !solaris

package compose

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

//go:build !solaris
// +build !solaris

package compose

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

//go:build !solaris
// +build !solaris

package compose

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

//go:build !solaris
// +build !solaris

package docker

import (
Expand Down

0 comments on commit 81fe3bc

Please sign in to comment.