forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extensions/observer/cfgardenobserver] New component skeleton
Co-authored-by: Cem Deniz Kabakci <cem.kabakci@springer.com>
- Loading branch information
Showing
27 changed files
with
602 additions
and
2 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] |
Validating CODEOWNERS rules …
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
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 @@ | ||
# CF 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) | | ||
|
||
[development]: https://github.com/open-telemetry/opentelemetry-collector#development | ||
<!-- end autogenerated section --> | ||
|
||
Cloudfoundry 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, default 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 | `"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,26 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cfgardenobserver // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver" | ||
|
||
import ( | ||
"errors" // Config defines configuration for cf garden observer. | ||
"time" | ||
) | ||
|
||
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 how frequency at which the observer | ||
// needs to poll for collecting information about new processes. | ||
RefreshInterval time.Duration `mapstructure:"refresh_interval"` | ||
} | ||
|
||
func (config Config) Validate() error { | ||
if config.Endpoint == "" { | ||
return errors.New("endpoint must be specified") | ||
} | ||
|
||
return nil | ||
} |
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,52 @@ | ||
// 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: NewFactory().CreateDefaultConfig(), | ||
}, | ||
{ | ||
id: component.NewIDWithName(metadata.Type, "all_settings"), | ||
expected: &Config{ | ||
Endpoint: "unix:///var/vcap/data/garden/garden.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,42 @@ | ||
// 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" | ||
) | ||
|
||
type cfGardenObserver struct { | ||
*observer.EndpointsWatcher | ||
} | ||
|
||
var _ extension.Extension = (*cfGardenObserver)(nil) | ||
|
||
func newObserver(params extension.Settings, config *Config) (extension.Extension, error) { | ||
g := &cfGardenObserver{} | ||
g.EndpointsWatcher = observer.NewEndpointsWatcher(g, time.Second, params.Logger) | ||
|
||
return g, nil | ||
} | ||
|
||
func (g *cfGardenObserver) Start(context.Context, component.Host) error { | ||
return nil | ||
} | ||
|
||
func (g *cfGardenObserver) Shutdown(context.Context) error { | ||
return 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,37 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cfgardenobserver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"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) | ||
|
||
time.Sleep(500 * time.Millisecond) // Wait a bit to sync endpoints once. | ||
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,42 @@ | ||
// 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 = 60 | ||
) | ||
|
||
// 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 * time.Second, | ||
} | ||
} | ||
|
||
func createExtension( | ||
_ context.Context, | ||
params extension.Settings, | ||
cfg component.Config, | ||
) (extension.Extension, error) { | ||
return newObserver(params, cfg.(*Config)) | ||
} |
Oops, something went wrong.