Skip to content

Commit

Permalink
observer extension: Rename protocol to transport_protocol (#473)
Browse files Browse the repository at this point in the history
* observer extension: Rename protocol to transport_protocol

* Address feedback
  • Loading branch information
asuresh4 committed Jul 20, 2020
1 parent ba9767e commit 102cde6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 29 deletions.
10 changes: 5 additions & 5 deletions extension/observer/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ type Pod struct {

// Port is an endpoint that has a target as well as a port.
type Port struct {
Name string
Pod Pod
Port uint16
Protocol Protocol
Name string
Pod Pod
Port uint16
Transport Transport
}

type EndpointEnv map[string]interface{}
Expand Down Expand Up @@ -81,7 +81,7 @@ func EndpointToEnv(endpoint Endpoint) (EndpointEnv, error) {
"labels": o.Pod.Labels,
"annotations": o.Pod.Annotations,
},
"protocol": o.Protocol,
"transport": o.Transport,
}, nil

default:
Expand Down
6 changes: 3 additions & 3 deletions extension/observer/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func TestEndpointToEnv(t *testing.T) {
"annotation_1": "value_1",
},
},
Port: 2379,
Protocol: ProtocolTCP,
Port: 2379,
Transport: ProtocolTCP,
},
},
want: EndpointEnv{
Expand All @@ -94,7 +94,7 @@ func TestEndpointToEnv(t *testing.T) {
"annotation_1": "value_1",
},
},
"protocol": ProtocolTCP,
"transport": ProtocolTCP,
},
wantErr: false,
},
Expand Down
10 changes: 5 additions & 5 deletions extension/observer/k8sobserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func (h *handler) convertPodToEndpoints(pod *v1.Pod) []observer.Endpoint {
ID: endpointID,
Target: fmt.Sprintf("%s:%d", podIP, port.ContainerPort),
Details: observer.Port{
Pod: podDetails,
Name: port.Name,
Port: uint16(port.ContainerPort),
Protocol: getProtocol(port.Protocol),
Pod: podDetails,
Name: port.Name,
Port: uint16(port.ContainerPort),
Transport: getTransport(port.Protocol),
},
})
}
Expand All @@ -97,7 +97,7 @@ func (h *handler) convertPodToEndpoints(pod *v1.Pod) []observer.Endpoint {
return endpoints
}

func getProtocol(protocol v1.Protocol) observer.Protocol {
func getTransport(protocol v1.Protocol) observer.Transport {
switch protocol {
case v1.ProtocolTCP:
return observer.ProtocolTCP
Expand Down
12 changes: 6 additions & 6 deletions extension/observer/k8sobserver/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestEndpointsAdded(t *testing.T) {
Name: "pod-2",
Labels: map[string]string{"env": "prod"},
},
Port: 443,
Protocol: observer.ProtocolTCP,
Port: 443,
Transport: observer.ProtocolTCP,
},
}}, sink.added)
assert.Nil(t, sink.removed)
Expand Down Expand Up @@ -78,8 +78,8 @@ func TestEndpointsRemoved(t *testing.T) {
Name: "pod-2",
Labels: map[string]string{"env": "prod"},
},
Port: 443,
Protocol: observer.ProtocolTCP,
Port: 443,
Transport: observer.ProtocolTCP,
},
}}, sink.removed)
assert.Nil(t, sink.added)
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestEndpointsChanged(t *testing.T) {
Name: "https", Pod: observer.Pod{
Name: "pod-2",
Labels: map[string]string{"env": "prod", "updated-label": "true"}},
Port: 443,
Protocol: observer.ProtocolTCP}},
Port: 443,
Transport: observer.ProtocolTCP}},
}, sink.changed)
}
18 changes: 13 additions & 5 deletions extension/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@

package observer

// Protocol defines network protocol for container ports.
type Protocol string
// Transport defines protocol for ports.
type Transport string

const (
// ProtocolTCP is the TCP protocol.
ProtocolTCP Protocol = "TCP"
ProtocolTCP Transport = "TCP"
// ProtocolTCP4 is the TCP4 protocol.
ProtocolTCP4 Transport = "TCP4"
// ProtocolTCP6 is the TCP6 protocol.
ProtocolTCP6 Transport = "TCP6"
// ProtocolUDP is the UDP protocol.
ProtocolUDP Protocol = "UDP"
ProtocolUDP Transport = "UDP"
// ProtocolUDP4 is the UDP4 protocol.
ProtocolUDP4 Transport = "UDP4"
// ProtocolUDP6 is the UDP6 protocol.
ProtocolUDP6 Transport = "UDP6"
// ProtocolUnknown is some other protocol or it is unknown.
ProtocolUnknown Protocol = "Unknown"
ProtocolUnknown Transport = "Unknown"
)

// Observable is an interface that provides notification of endpoint changes.
Expand Down
4 changes: 3 additions & 1 deletion receiver/receivercreator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ Each rule must start with `type.(pod|port) &&` such that the rule matches only o
| pod.name | name of the owning pod |
| pod.labels | map of labels of the owning pod |
| pod.annotations | map of annotations of the owning pod |
| protocol | "TCP" or "UDP" |
| protocol | `TCP` or `UDP` |



## Example

Expand Down
8 changes: 4 additions & 4 deletions receiver/receivercreator/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ var portEndpoint = observer.Endpoint{
ID: "port-1",
Target: "localhost:1234",
Details: observer.Port{
Name: "http",
Pod: pod,
Port: 1234,
Protocol: observer.ProtocolTCP,
Name: "http",
Pod: pod,
Port: 1234,
Transport: observer.ProtocolTCP,
},
}

Expand Down

0 comments on commit 102cde6

Please sign in to comment.