forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the start of a basic memcached receiver. It scrapes some basic metrics from a memcached instance and sends them along. The primary test of the metric generation logic is in the integration test due to the relative opacity of the memcached protocol and the lack of any preexisting mock (the integration test uses a real memcached instance via Docker containers). There are only five basic metrics to start with but this can be easily expanded with this framework.
- Loading branch information
1 parent
6e84f52
commit 8662fd6
Showing
14 changed files
with
2,199 additions
and
0 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
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,39 @@ | ||
# Memcached Receiver | ||
|
||
This receiver can fetch stats from a Memcached instance using the [stats | ||
command](https://github.com/memcached/memcached/wiki/Commands#statistics). A | ||
detailed description of all the stats available is at | ||
https://github.com/memcached/memcached/blob/master/doc/protocol.txt#L1159. | ||
|
||
> :construction: This receiver is currently in **BETA**. | ||
## Details | ||
|
||
## Configuration | ||
|
||
> :information_source: This receiver is in beta and configuration fields are subject to change. | ||
The following settings are required: | ||
|
||
- `endpoint` (default: `localhost:11211`): The hostname/IP address and port of the memcached instance | ||
|
||
The following settings are optional: | ||
|
||
- `collection_interval` (default = `10s`): This receiver runs on an interval. | ||
Each time it runs, it queries memcached, creates metrics, and sends them to the | ||
next consumer. The `collection_interval` configuration option tells this | ||
receiver the duration between runs. This value must be a string readable by | ||
Golang's `ParseDuration` function (example: `1h30m`). Valid time units are | ||
`ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`. | ||
|
||
Example: | ||
|
||
```yaml | ||
receivers: | ||
memcached: | ||
endpoint: "localhost:11211" | ||
collection_interval: 10s | ||
``` | ||
|
||
The full list of settings exposed for this receiver are documented [here](./config.go) | ||
with detailed sample configurations [here](./testdata/config.yaml). |
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,32 @@ | ||
// Copyright 2020, 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:https://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 memcachedreceiver | ||
|
||
import ( | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/config/confignet" | ||
"go.opentelemetry.io/collector/receiver/receiverhelper" | ||
) | ||
|
||
type config struct { | ||
configmodels.ReceiverSettings `mapstructure:",squash"` | ||
receiverhelper.ScraperControllerSettings `mapstructure:",squash"` | ||
confignet.TCPAddr `mapstructure:",squash"` | ||
|
||
// Timeout for the memcache stats request | ||
Timeout time.Duration `mapstructure:"timeout"` | ||
} |
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,72 @@ | ||
// Copyright 2020, 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:https://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 memcachedreceiver | ||
|
||
//go:generate mdatagen metadata.yaml | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/config/confignet" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/receiver/receiverhelper" | ||
) | ||
|
||
const ( | ||
typeStr = "memcached" | ||
) | ||
|
||
// NewFactory creates a factory for memcached receiver. | ||
func NewFactory() component.ReceiverFactory { | ||
return receiverhelper.NewFactory( | ||
typeStr, | ||
createDefaultConfig, | ||
receiverhelper.WithMetrics(createMetricsReceiver)) | ||
} | ||
|
||
func createDefaultConfig() configmodels.Receiver { | ||
return &config{ | ||
ReceiverSettings: configmodels.ReceiverSettings{ | ||
TypeVal: typeStr, | ||
NameVal: typeStr, | ||
}, | ||
ScraperControllerSettings: receiverhelper.ScraperControllerSettings{ | ||
CollectionInterval: 10 * time.Second, | ||
}, | ||
Timeout: 10 * time.Second, | ||
TCPAddr: confignet.TCPAddr{ | ||
Endpoint: "localhost:11211", | ||
}, | ||
} | ||
} | ||
|
||
func createMetricsReceiver( | ||
ctx context.Context, | ||
params component.ReceiverCreateParams, | ||
rConf configmodels.Receiver, | ||
consumer consumer.MetricsConsumer, | ||
) (component.MetricsReceiver, error) { | ||
cfg := rConf.(*config) | ||
|
||
scraper := newMemcachedScraper(params.Logger, cfg) | ||
|
||
return receiverhelper.NewScraperControllerReceiver( | ||
&cfg.ScraperControllerSettings, consumer, | ||
receiverhelper.AddResourceMetricsScraper(scraper), | ||
) | ||
} |
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,56 @@ | ||
// Copyright 2020, 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:https://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 memcachedreceiver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/configcheck" | ||
"go.opentelemetry.io/collector/receiver/receiverhelper" | ||
"go.opentelemetry.io/collector/testbed/testbed" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestType(t *testing.T) { | ||
factory := NewFactory() | ||
ft := factory.Type() | ||
require.EqualValues(t, "memcached", ft) | ||
} | ||
|
||
func TestValidConfig(t *testing.T) { | ||
factory := NewFactory() | ||
err := configcheck.ValidateConfig(factory.CreateDefaultConfig()) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestCreateMetricsReceiver(t *testing.T) { | ||
factory := NewFactory() | ||
metricsReceiver, err := factory.CreateMetricsReceiver( | ||
context.Background(), | ||
component.ReceiverCreateParams{Logger: zap.NewNop()}, | ||
&config{ | ||
ScraperControllerSettings: receiverhelper.ScraperControllerSettings{ | ||
CollectionInterval: 10 * time.Second, | ||
}, | ||
}, | ||
&testbed.MockMetricConsumer{}, | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, metricsReceiver) | ||
} |
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 @@ | ||
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/memcachedreceiver | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/census-instrumentation/opencensus-proto v0.3.0 | ||
github.com/davecgh/go-spew v1.1.1 | ||
github.com/go-redis/redis/v7 v7.4.0 | ||
github.com/grobie/gomemcache v0.0.0-20180201122607-1f779c573665 | ||
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.0.0-00010101000000-000000000000 | ||
github.com/stretchr/testify v1.6.1 | ||
go.opentelemetry.io/collector v0.13.1-0.20201027215027-6ae66159741d | ||
go.uber.org/zap v1.16.0 | ||
google.golang.org/api v0.32.0 | ||
google.golang.org/protobuf v1.25.0 | ||
) | ||
|
||
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common |
Oops, something went wrong.