forked from open-telemetry/opentelemetry-collector
-
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.
Implement OTLP/HTTP X-Protobuf Receiver
This change adds application/x-protobuf support to the existing grpc-gateway mux in the OTLP receiver. See: https://github.com/open-telemetry/oteps/blob/master/text/0099-otlp-http.md What currently works: * The receiver will correctly process HTTP requests with the Content-Type application/x-protobuf. * The receiver will respond with Content-Type application/x-protobuf. * The receiver will respond with status code HTTP 200 OK on success. What doesn't work yet: * The receiver cannot handle gzip-encoded requests (Content-Encoding gzip). * The receiver will not gzip-encode responses to requests with Accept-Encoding: gzip. Updates open-telemetry#881
- Loading branch information
1 parent
daf2fc7
commit 054b75f
Showing
3 changed files
with
168 additions
and
1 deletion.
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,52 @@ | ||
// 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 otlpreceiver | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
) | ||
|
||
// xProtobufMarshaler is a Marshaler which wraps runtime.ProtoMarshaller | ||
// and sets ContentType to application/x-protobuf | ||
type xProtobufMarshaler struct { | ||
marshaler runtime.ProtoMarshaller | ||
} | ||
|
||
// ContentType always returns "application/x-protobuf". | ||
func (*xProtobufMarshaler) ContentType() string { | ||
return "application/x-protobuf" | ||
} | ||
|
||
// Marshal marshals "value" into Proto | ||
func (m *xProtobufMarshaler) Marshal(value interface{}) ([]byte, error) { | ||
return m.marshaler.Marshal(value) | ||
} | ||
|
||
// Unmarshal unmarshals proto "data" into "value" | ||
func (m *xProtobufMarshaler) Unmarshal(data []byte, value interface{}) error { | ||
return m.marshaler.Unmarshal(data, value) | ||
} | ||
|
||
// NewDecoder returns a Decoder which reads proto stream from "reader". | ||
func (m *xProtobufMarshaler) NewDecoder(reader io.Reader) runtime.Decoder { | ||
return m.marshaler.NewDecoder(reader) | ||
} | ||
|
||
// NewEncoder returns an Encoder which writes proto stream into "writer". | ||
func (m *xProtobufMarshaler) NewEncoder(writer io.Writer) runtime.Encoder { | ||
return m.marshaler.NewEncoder(writer) | ||
} |