Skip to content

Commit

Permalink
[receiver/purefa] Bootstrap component (open-telemetry#14969)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoscn committed Nov 28, 2022
1 parent 265d9f6 commit d733380
Show file tree
Hide file tree
Showing 16 changed files with 824 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ receiver/prometheusexecreceiver/ @open-telemetry/collector-c
receiver/prometheusreceiver/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @dashpole
receiver/rabbitmqreceiver/ @open-telemetry/collector-contrib-approvers @djaglowski @cpheps
receiver/pulsarreceiver/ @open-telemetry/collector-contrib-approvers @dmitryax @tjiuming
receiver/purefareceiver/ @open-telemetry/collector-contrib-approvers @jpkrohling @dgoscn @chrroberts-pure
receiver/receivercreator/ @open-telemetry/collector-contrib-approvers @jrcamp
receiver/redisreceiver/ @open-telemetry/collector-contrib-approvers @pmcollins @dmitryax
receiver/riakreceiver/ @open-telemetry/collector-contrib-approvers @djaglowski @armstrmi
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ body:
- receiver/prometheus
- receiver/prometheusexec
- receiver/pulsar
- receiver/purefa
- receiver/rabbitmq
- receiver/receivercreator
- receiver/redis
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ body:
- receiver/prometheus
- receiver/prometheusexec
- receiver/pulsar
- receiver/purefa
- receiver/rabbitmq
- receiver/receivercreator
- receiver/redis
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ body:
- receiver/prometheus
- receiver/prometheusexec
- receiver/pulsar
- receiver/purefa
- receiver/rabbitmq
- receiver/receivercreator
- receiver/redis
Expand Down
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,10 @@ updates:
directory: "/receiver/pulsarreceiver"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/receiver/purefareceiver"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/receiver/rabbitmqreceiver"
schedule:
Expand Down
1 change: 1 addition & 0 deletions receiver/purefareceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
51 changes: 51 additions & 0 deletions receiver/purefareceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Pure Storage FlashArray Receiver

| Status | |
| ------------------------ |---------------------|
| Stability | [in-development] |
| Supported pipeline types | metrics |
| Distributions | [contrib] |

The Pure Storage FlashArray receiver, receives metrics from Pure Storage internal services hosts.

Supported pipeline types: metrics

## Configuration

The following settings are required:
- `endpoint` (default: `http:https://172.0.0.0:9490/metrics/array`): The URL of the scraper selected endpoint

Example:

```yaml
extensions:
bearertokenauth/array01:
token: "some-token"
bearertokenauth/array02:
token: "some-other-token"

receivers:
purefa:
endpoint: http:https://172.0.0.0:9490/metrics/
arrays:
- address: gse-array01
auth: bearertokenauth/array01
- address: gse-array02
auth: bearertokenauth/array02
hosts:
- address: gse-array01
auth: bearertokenauth/array01
settings:
reload_intervals:
array: 10s
host: 1m
volume: 2m
pods: 15s
directories: 15s
```

The full list of settings exposed for this receiver are documented [here](./config.go)
with detailed sample configurations [here](./testdata/config.yaml).

[in-development]: https://github.com/open-telemetry/opentelemetry-collector#in-development
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
56 changes: 56 additions & 0 deletions receiver/purefareceiver/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2022 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: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 purefareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver"

import (
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/confighttp"
)

var _ component.ReceiverConfig = (*Config)(nil)

// Config relating to Array Metric Scraper.
type Config struct {
config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
confighttp.HTTPClientSettings `mapstructure:",squash"`

// Settings contains settings for the individual scrapers
Settings *Settings `mapstructure:"settings"`

// Arrays represents the list of arrays to query
Arrays []Array `mapstructure:"arrays"`
}

type Array struct {
Address string `mapstructure:"address"`
Auth configauth.Authentication `mapstructure:"auth"`
}

type Settings struct {
ReloadIntervals *ReloadIntervals `mapstructure:"reload_intervals"`
}

type ReloadIntervals struct {
Array time.Duration `mapstructure:"array"`
}

func (c *Config) Validate() error {
// TODO(dgoscn): perform config validation
return nil
}
60 changes: 60 additions & 0 deletions receiver/purefareceiver/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2022 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: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 purefareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver"

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/confmap/confmaptest"
)

func TestLoadConfig(t *testing.T) {
t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)

tests := []struct {
id component.ID
expected component.ReceiverConfig
}{
{
id: component.NewID(typeStr),
expected: &Config{
ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)),
},
},
// TODO(dgoscn): testar with_custom_intervals
}

for _, tt := range tests {
t.Run(tt.id.String(), func(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

sub, err := cm.Sub(tt.id.String())
require.NoError(t, err)
require.NoError(t, component.UnmarshalReceiverConfig(sub, cfg))

assert.NoError(t, component.ValidateConfig(cfg))
assert.Equal(t, tt.expected, cfg)
})
}
}
42 changes: 42 additions & 0 deletions receiver/purefareceiver/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 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: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 purefareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver"

// This file implements Factory for Array scraper.
import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confighttp"
)

// NewFactory creates a factory for Pure Storage FlashArray receiver.
const (
typeStr = "purefa"
stability = component.StabilityLevelDevelopment
)

func NewFactory() component.ReceiverFactory {
return component.NewReceiverFactory(
typeStr,
createDefaultConfig,
component.WithMetricsReceiver(createMetricsReceiver, stability))
}

func createDefaultConfig() component.ReceiverConfig {
return &Config{
ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)),
HTTPClientSettings: confighttp.HTTPClientSettings{},
}
}
50 changes: 50 additions & 0 deletions receiver/purefareceiver/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2022 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: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 purefareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver"

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
)

func TestTypeStr(t *testing.T) {
factory := NewFactory()

assert.Equal(t, "purefa", string(factory.Type()))
}

func TestCreateDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
}

func TestCreateReceiver(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
set := componenttest.NewNopReceiverCreateSettings()
mReceiver, err := factory.CreateMetricsReceiver(context.Background(), set, cfg, nil)
assert.NoError(t, err, "receiver creation failed")
assert.Nil(t, mReceiver, "receiver creation failed")

tReceiver, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil)
assert.Equal(t, err, component.ErrDataTypeIsNotSupported)
assert.Nil(t, tReceiver)
}
49 changes: 49 additions & 0 deletions receiver/purefareceiver/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver

go 1.18

require (
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/collector v0.66.0
go.opentelemetry.io/collector/component v0.66.0
go.opentelemetry.io/collector/consumer v0.66.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // 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.12 // indirect
github.com/knadh/koanf v1.4.4 // 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/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.8.2 // indirect
go.opentelemetry.io/collector/featuregate v0.65.0 // indirect
go.opentelemetry.io/collector/pdata v0.66.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/metric v0.33.0 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit d733380

Please sign in to comment.