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.
* Add http_forwarder skeleton * Address feedback * Address feedback
- Loading branch information
Showing
8 changed files
with
1,512 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
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,26 @@ | ||
# HTTP Forwarder Extension | ||
|
||
This extension accepts HTTP requests, optionally adds headers to them and forwards them. | ||
The RequestURIs of the original requests are preserved by the extension. | ||
|
||
## Configuration | ||
|
||
* `ingress`: HTTP config settings for HTTP server listening to requests. | ||
* `endpoint` (default: `localhost:6060`): The host to which requests should be forwarded to. | ||
* `egress`: HTTP config settings to use for forwarding requests. | ||
* `endpoint` (**required**): The target to which requests should be forwarded to. | ||
* `headers` (default: `nil`): Additional headers to be added to all requests passing through the extension. | ||
* `timeout` (default: `10s`): How long to wait for each request to complete. | ||
|
||
### Example | ||
|
||
```yaml | ||
http_forwarder: | ||
ingress: | ||
endpoint: localhost:7070 | ||
egress: | ||
endpoint: http:https://target/ | ||
headers: | ||
otel_http_forwarder: dev | ||
timeout: 5s | ||
``` |
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,31 @@ | ||
// 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: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 httpforwarder | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
) | ||
|
||
// Config defines configuration for http forwarder extension. | ||
type Config struct { | ||
configmodels.ExtensionSettings `mapstructure:",squash"` | ||
|
||
// Ingress holds config settings for HTTP server listening for requests. | ||
Ingress confighttp.HTTPServerSettings `mapstructure:"ingress"` | ||
|
||
// Egress holds config settings to use for forwarded requests. | ||
Egress confighttp.HTTPClientSettings `mapstructure:"egress"` | ||
} |
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 | ||
// | ||
// 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 httpforwarder | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
type httpForwarder struct { | ||
} | ||
|
||
var _ component.ServiceExtension = (*httpForwarder)(nil) | ||
|
||
func (h httpForwarder) Start(_ context.Context, _ component.Host) error { | ||
// TODO: Start HTTP server | ||
return nil | ||
} | ||
|
||
func (h httpForwarder) Shutdown(_ context.Context) error { | ||
// TODO: Shutdown HTTP server | ||
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,65 @@ | ||
// 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: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 httpforwarder | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/extension/extensionhelper" | ||
) | ||
|
||
const ( | ||
// The value of extension "type" in configuration. | ||
typeStr configmodels.Type = "http_forwarder" | ||
|
||
// Default endpoints to bind to. | ||
defaultEndpoint = ":6060" | ||
) | ||
|
||
// NewFactory creates a factory for HostObserver extension. | ||
func NewFactory() component.ExtensionFactory { | ||
return extensionhelper.NewFactory( | ||
typeStr, | ||
createDefaultConfig, | ||
createExtension) | ||
} | ||
|
||
func createDefaultConfig() configmodels.Extension { | ||
return &Config{ | ||
ExtensionSettings: configmodels.ExtensionSettings{ | ||
TypeVal: typeStr, | ||
NameVal: string(typeStr), | ||
}, | ||
Ingress: confighttp.HTTPServerSettings{ | ||
Endpoint: defaultEndpoint, | ||
}, | ||
Egress: confighttp.HTTPClientSettings{ | ||
Timeout: 10 * time.Second, | ||
}, | ||
} | ||
} | ||
|
||
func createExtension( | ||
_ context.Context, | ||
_ component.ExtensionCreateParams, | ||
_ configmodels.Extension, | ||
) (component.ServiceExtension, error) { | ||
// TODO: Return httpForwarder | ||
return nil, 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,35 @@ | ||
// 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: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 httpforwarder | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
) | ||
|
||
func TestFactory(t *testing.T) { | ||
f := NewFactory() | ||
expectType := "http_forwarder" | ||
require.Equal(t, configmodels.Type(expectType), f.Type()) | ||
|
||
cfg := f.CreateDefaultConfig().(*Config) | ||
require.Equal(t, expectType, cfg.Name()) | ||
require.Equal(t, configmodels.Type(expectType), cfg.Type()) | ||
require.Equal(t, ":6060", cfg.Ingress.Endpoint) | ||
require.Equal(t, 10*time.Second, cfg.Egress.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,9 @@ | ||
module github.com/open-telemetry/opentelemetry-collector-contrib/extension/httpforwarder | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/stretchr/testify v1.6.1 | ||
go.opentelemetry.io/collector v0.9.1-0.20200903224024-3eb3b664a832 | ||
go.uber.org/zap v1.15.0 | ||
) |
Oops, something went wrong.