-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[observer/cfgarden] New component (#33727)
**Description:** We would like to implement a new observer for [Cloudfoundry](https://www.cloudfoundry.org/) containers/applications. The idea is not make use of the main API but the local one, which is available as unix socket on each node and manages the containers lifecycle. The main API would remain as optional and only to get Application info (which only involves one GET http request once the app id is known). **Link to tracking Issue:** [33618](#33618) **Testing:** First component PR **Documentation:** Added Readme --------- Co-authored-by: Tomás Mota <tomas.mota@springernature.com> Co-authored-by: Jose Riguera <jose.riguera@springer.com> Co-authored-by: Tomás Mota <tomasmota@hey.com> Co-authored-by: Curtis Robert <crobert@splunk.com> Co-authored-by: José Riguera Lopez <jriguera@gmail.com>
- Loading branch information
1 parent
fd17b88
commit 26cc3d6
Showing
30 changed files
with
612 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: new_component | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: extensions/observer/cfgardenobserver | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add a new observer that discovers containers through the Garden API | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [33618] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,7 @@ rlankfo | |
swar8080 | ||
zpzhuSplunk | ||
thmshmm | ||
cemdk | ||
tomasmota | ||
m1rp | ||
jriguera |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Cloud Foundry Garden Observer Extension | ||
|
||
<!-- status autogenerated section --> | ||
| Status | | | ||
| ------------- |-----------| | ||
| Stability | [development] | | ||
| Distributions | [] | | ||
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aextension%2Fcfgardenobserver%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fcfgardenobserver) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aextension%2Fcfgardenobserver%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fcfgardenobserver) | | ||
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@crobert-1](https://www.github.com/crobert-1), [@cemdk](https://www.github.com/cemdk), [@tomasmota](https://www.github.com/tomasmota), [@m1rp](https://www.github.com/m1rp), [@jriguera](https://www.github.com/jriguera) | | ||
|
||
[development]: https://github.com/open-telemetry/opentelemetry-collector#development | ||
<!-- end autogenerated section --> | ||
|
||
Cloud Foundry (CF) is a platform as a service (PaaS) which has implemented their own container technology. The component in charge of providing a local API in each node (also known as "diego-cell") is named Garden. | ||
|
||
The `cfgarden_observer` looks at the current host to discover Garden containers. | ||
|
||
## Example Config | ||
|
||
```yaml | ||
extensions: | ||
cfgarden_observer: | ||
# url of the Garden socket, defaults to unix:///var/vcap/data/garden/garden.sock | ||
endpoint: my/path/to/garden.sock | ||
# determines how often to look for changes in endpoints. | ||
refresh_interval: 30s | ||
|
||
receivers: | ||
receiver_creator: | ||
watch_observers: [cfgarden_observer] | ||
receivers: | ||
prometheus_simple: | ||
rule: type == "container" && name == "myapp" | ||
config: | ||
metrics_path: /metrics | ||
endpoint: '`endpoint`' | ||
``` | ||
### Configuration | ||
| Name | Type | Default | Docs | | ||
|------------------|--------|------------------------------------------|--------------------------------------------------------| | ||
| refresh_interval | string | 60s | Determines how often to look for changes in endpoints. | | ||
| endpoint | string | unix:///var/vcap/data/garden/garden.sock | The endpoint to connect to the Garden API. | | ||
### Endpoint Variables | ||
Endpoint variables exposed by this observer are as follows. | ||
| Variable | Description | | ||
|-----------|--------------------------------------------------------------------------------------------| | ||
| type | this value is always `container` | | ||
| name | name of the Garden container associated to the port | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cfgardenobserver // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver" | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// Config defines configuration for CF Garden observer. | ||
type Config struct { | ||
// The URL of the CF Garden api. Default is "unix:///var/vcap/data/garden/garden.sock" | ||
Endpoint string `mapstructure:"endpoint"` | ||
|
||
// RefreshInterval determines the frequency at which the observer | ||
// needs to poll for collecting information about new processes. | ||
RefreshInterval time.Duration `mapstructure:"refresh_interval"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cfgardenobserver | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/confmap/confmaptest" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver/internal/metadata" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
id component.ID | ||
expected component.Config | ||
}{ | ||
{ | ||
id: component.NewID(metadata.Type), | ||
expected: &Config{ | ||
Endpoint: "unix:///var/vcap/data/garden/garden.sock", | ||
RefreshInterval: 1 * time.Minute, | ||
}, | ||
}, | ||
{ | ||
id: component.NewIDWithName(metadata.Type, "all_settings"), | ||
expected: &Config{ | ||
Endpoint: "unix:///var/vcap/data/garden/custom.sock", | ||
RefreshInterval: 20 * time.Second, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.id.String(), func(t *testing.T) { | ||
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) | ||
require.NoError(t, err) | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
sub, err := cm.Sub(tt.id.String()) | ||
require.NoError(t, err) | ||
require.NoError(t, sub.Unmarshal(cfg)) | ||
|
||
assert.NoError(t, component.ValidateConfig(cfg)) | ||
assert.Equal(t, tt.expected, cfg) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:generate mdatagen metadata.yaml | ||
|
||
package cfgardenobserver // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cfgardenobserver // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver" | ||
|
||
import ( | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/extension" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer" | ||
) | ||
|
||
type cfGardenObserver struct { | ||
*observer.EndpointsWatcher | ||
|
||
component.StartFunc | ||
component.ShutdownFunc | ||
} | ||
|
||
var _ extension.Extension = (*cfGardenObserver)(nil) | ||
|
||
func newObserver(params extension.Settings, _ *Config) (extension.Extension, error) { | ||
g := &cfGardenObserver{} | ||
g.EndpointsWatcher = observer.NewEndpointsWatcher(g, time.Second, params.Logger) | ||
|
||
return g, nil | ||
} | ||
|
||
func (g *cfGardenObserver) ListEndpoints() []observer.Endpoint { | ||
// TODO: Implement the logic to list the endpoints. | ||
endpoints := make([]observer.Endpoint, 0) | ||
|
||
return endpoints | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cfgardenobserver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/extension/extensiontest" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer" | ||
) | ||
|
||
func TestStartAndStopObserver(t *testing.T) { | ||
factory := NewFactory() | ||
params := extensiontest.NewNopSettings() | ||
ext, err := newObserver(params, factory.CreateDefaultConfig().(*Config)) | ||
require.NoError(t, err) | ||
require.NotNil(t, ext) | ||
|
||
obvs, ok := ext.(*cfGardenObserver) | ||
require.True(t, ok) | ||
|
||
ctx := context.Background() | ||
require.NoError(t, obvs.Start(ctx, componenttest.NewNopHost())) | ||
|
||
expected := obvs.ListEndpoints() | ||
want := []observer.Endpoint{} | ||
require.Equal(t, want, expected) | ||
|
||
require.NoError(t, obvs.Shutdown(ctx)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cfgardenobserver // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver" | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/extension" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver/internal/metadata" | ||
) | ||
|
||
const ( | ||
defaultCollectionInterval = 1 * time.Minute | ||
defaultEndpoint = "unix:///var/vcap/data/garden/garden.sock" | ||
) | ||
|
||
// NewFactory creates a factory for HostObserver extension. | ||
func NewFactory() extension.Factory { | ||
return extension.NewFactory( | ||
metadata.Type, | ||
createDefaultConfig, | ||
createExtension, | ||
metadata.ExtensionStability, | ||
) | ||
} | ||
|
||
func createDefaultConfig() component.Config { | ||
return &Config{ | ||
RefreshInterval: defaultCollectionInterval, | ||
Endpoint: defaultEndpoint, | ||
} | ||
} | ||
|
||
func createExtension( | ||
_ context.Context, | ||
params extension.Settings, | ||
cfg component.Config, | ||
) (extension.Extension, error) { | ||
return newObserver(params, cfg.(*Config)) | ||
} |
Oops, something went wrong.