-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[receiver/expvarreceiver] Overall structure for new expvarreceiver #9747
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b4b383c
initial configs and skeleton for expvarreceiver
jamesmoessis 4bdb1eb
make goporto
jamesmoessis 29372ca
add changelog entry
jamesmoessis 11913bb
add jamesmoessis and moviestoreguy as codeowners for expvarreceiver
jamesmoessis 1b3f1dd
correct versions
jamesmoessis 5920c17
add expvarreceiver to versions.yaml
jamesmoessis 9f64908
Merge branch 'main' into expvarrecevier
jamesmoessis f655ea8
switch to using scraperhelper for config settings
jamesmoessis 117f1cd
go mod tidy
jamesmoessis ec70ba3
Update receiver/expvarreceiver/Makefile
jamesmoessis bca1c00
cleanup todos
jamesmoessis 562b682
squash the http client config as per review
jamesmoessis 8022479
Merge branch 'main' into expvarrecevier
jamesmoessis 74963de
add changelog entry
jamesmoessis 4230324
update collector dependency version
jamesmoessis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,48 @@ | ||
# Expvar Receiver | ||
|
||
An Expvar Receiver scrapes metrics from [expvar](https://pkg.go.dev/expvar), | ||
which exposes data in JSON format from an HTTP endpoint. The metrics are | ||
extracted from the `expvar` variable [memstats](https://pkg.go.dev/runtime#MemStats), | ||
which exposes various information about the Go runtime. | ||
|
||
> :construction: This receiver is in development and incomplete. It should not be used yet. | ||
|
||
## Configuration | ||
|
||
### Default | ||
|
||
By default, without any configuration, a request will be sent to `http://localhost:8080/debug/vars` | ||
every 60 seconds. The default configuration is achieved by the following: | ||
|
||
```yaml | ||
receivers: | ||
expvar: | ||
``` | ||
|
||
### Customising | ||
|
||
The following can be configured: | ||
- Configure the HTTP client for scraping the expvar variables. The full set of | ||
configuration options for the client can be found in the core repo's | ||
[confighttp](https://github.com/open-telemetry/opentelemetry-collector/tree/main/config/confighttp#client-configuration). | ||
- defaults: | ||
- `endpoint = http://localhost:8080/debug/vars` | ||
- `timeout = 3s` | ||
- `collection_interval` - Configure how often the metrics are scraped. | ||
- default: 1m | ||
- `metrics` - Enable or disable metrics by name. | ||
|
||
### Example configuration | ||
|
||
```yaml | ||
receivers: | ||
expvar: | ||
endpoint: "http://localhost:8000/custom/path" | ||
timeout: 1s | ||
collection_interval: 30s | ||
metrics: | ||
- name: example_metric.enabled | ||
enabled: true | ||
- name: example_metric.disabled | ||
enabled: false | ||
``` |
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,54 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed 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. | ||
|
||
package expvarreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/expvarreceiver" | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/receiver/scraperhelper" | ||
) | ||
|
||
type Config struct { | ||
scraperhelper.ScraperControllerSettings `mapstructure:",squash"` | ||
HTTP *confighttp.HTTPClientSettings `mapstructure:",squash"` | ||
MetricsConfig []MetricConfig `mapstructure:"metrics"` | ||
} | ||
|
||
type MetricConfig struct { | ||
Name string `mapstructure:"name"` | ||
Enabled bool `mapstructure:"enabled"` | ||
} | ||
|
||
var _ config.Receiver = (*Config)(nil) | ||
|
||
func (c *Config) Validate() error { | ||
if c.HTTP == nil { | ||
return fmt.Errorf("must specify http_client configuration when using expvar receiver") | ||
} | ||
u, err := url.Parse(c.HTTP.Endpoint) | ||
if err != nil { | ||
return fmt.Errorf("endpoint is not a valid URL: %v", err) | ||
} | ||
if u.Host == "" { | ||
return fmt.Errorf("host not found in HTTP endpoint") | ||
} | ||
if u.Scheme != "http" && u.Scheme != "https" { | ||
return fmt.Errorf("scheme must be 'http' or 'https', but was '%s'", u.Scheme) | ||
} | ||
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,68 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed 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. | ||
|
||
package expvarreceiver | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/service/servicetest" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
factories, err := componenttest.NopFactories() | ||
assert.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
factories.Receivers[typeStr] = factory | ||
cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
assert.Equal(t, 2, len(cfg.Receivers)) | ||
|
||
// Validate default config | ||
expectedCfg := factory.CreateDefaultConfig().(*Config) | ||
expectedCfg.SetIDName("default") | ||
|
||
assert.Equal(t, expectedCfg, cfg.Receivers[config.NewComponentIDWithName(typeStr, "default")]) | ||
|
||
// Validate custom config | ||
expectedCfg = factory.CreateDefaultConfig().(*Config) | ||
expectedCfg.SetIDName("custom") | ||
expectedCfg.CollectionInterval = time.Second * 30 | ||
expectedCfg.HTTP = &confighttp.HTTPClientSettings{ | ||
Endpoint: "http://localhost:8000/custom/path", | ||
Timeout: time.Second * 5, | ||
} | ||
expectedCfg.MetricsConfig = []MetricConfig{ | ||
{ | ||
Name: "example_metric.enabled", | ||
Enabled: true, | ||
}, | ||
{ | ||
Name: "example_metric.disabled", | ||
Enabled: false, | ||
}, | ||
} | ||
|
||
assert.Equal(t, expectedCfg, cfg.Receivers[config.NewComponentIDWithName(typeStr, "custom")]) | ||
} |
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,60 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed 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. | ||
|
||
package expvarreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/expvarreceiver" | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/receiver/scraperhelper" | ||
) | ||
|
||
const ( | ||
typeStr = "expvar" | ||
defaultEndpoint = "http://localhost:8000/debug/vars" | ||
defaultTimeout = 3 * time.Second | ||
) | ||
|
||
func NewFactory() component.ReceiverFactory { | ||
return component.NewReceiverFactory( | ||
typeStr, | ||
newDefaultConfig, | ||
component.WithMetricsReceiver(newMetricsReceiver)) | ||
} | ||
|
||
func newMetricsReceiver( | ||
ctx context.Context, | ||
settings component.ReceiverCreateSettings, | ||
rCfg config.Receiver, | ||
metrics consumer.Metrics, | ||
) (component.MetricsReceiver, error) { | ||
return nil, fmt.Errorf("not implemented") | ||
} | ||
|
||
func newDefaultConfig() config.Receiver { | ||
return &Config{ | ||
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(typeStr), | ||
HTTP: &confighttp.HTTPClientSettings{ | ||
Endpoint: defaultEndpoint, | ||
Timeout: defaultTimeout, | ||
}, | ||
MetricsConfig: []MetricConfig{}, | ||
} | ||
} |
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,45 @@ | ||
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/expvarreceiver | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/stretchr/testify v1.7.1 | ||
go.opentelemetry.io/collector v0.51.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/felixge/httpsnoop v1.0.2 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/compress v1.15.3 // indirect | ||
github.com/knadh/koanf v1.4.1 // indirect | ||
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rs/cors v1.8.2 // indirect | ||
go.opencensus.io v0.23.0 // indirect | ||
go.opentelemetry.io/collector/pdata v0.51.0 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0 // indirect | ||
go.opentelemetry.io/otel v1.7.0 // indirect | ||
go.opentelemetry.io/otel/metric v0.30.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.7.0 // indirect | ||
go.uber.org/atomic v1.9.0 // indirect | ||
go.uber.org/multierr v1.8.0 // indirect | ||
go.uber.org/zap v1.21.0 // indirect | ||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect | ||
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect | ||
google.golang.org/grpc v1.46.0 // indirect | ||
google.golang.org/protobuf v1.28.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we know the list of default metrics we are going to export, we should add them here in that PR with an example of how to disable them if you're not interested in
gc_pause.time
for example.