Skip to content

Commit 6513c7d

Browse files
committed
Relfect reviews
Signed-off-by: terashima <tomoya-terashima@cybozu.co.jp>
1 parent 6dfd603 commit 6513c7d

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

docs/cmd-coil-egress.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ This value is from the result of `iptables -t nat -L POSTROUTING -vn`.
8484
| `namespace` | The egress resource namespace |
8585
| `egress` | The egress resource name |
8686
| `pod` | The pod name |
87-
| `protocol` | Protocol name |
87+
| `protocol` | The protocol name |
8888

8989
### `coil_egress_nftables_masqueraded_bytes_total`
9090

@@ -96,7 +96,7 @@ This value is from the result of `iptables -t nat -L POSTROUTING -vn`.
9696
| `namespace` | The egress resource namespace |
9797
| `egress` | The egress resource name |
9898
| `pod` | The pod name |
99-
| `protocol` | Protocol name |
99+
| `protocol` | The protocol name |
100100

101101
### `coil_egress_nftables_invalid_packets_total`
102102

@@ -108,7 +108,7 @@ This value is from the result of `iptables -t filter -L -vn`.
108108
| `namespace` | The egress resource namespace |
109109
| `egress` | The egress resource name |
110110
| `pod` | The pod name |
111-
| `protocol` | Protocol name |
111+
| `protocol` | The protocol name |
112112

113113
### `coil_egress_nftables_invalid_bytes_total`
114114

@@ -120,5 +120,5 @@ This value is from the result of `iptables -t filter -L -vn`.
120120
| `namespace` | The egress resource namespace |
121121
| `egress` | The egress resource name |
122122
| `pod` | The pod name |
123-
| `protocol` | Protocol name |
123+
| `protocol` | The protocol name |
124124

v2/cmd/coil-egress/sub/run.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525

2626
const (
2727
gracefulTimeout = 5 * time.Second
28+
protocolIPv4 = "ipv4"
29+
protocolIpv6 = "ipv6"
2830
)
2931

3032
var (
@@ -37,8 +39,8 @@ func init() {
3739

3840
// +kubebuilder:scaffold:scheme
3941

40-
metrics.Registry.MustRegister(egressMetrics.NfConnctrackCount)
41-
metrics.Registry.MustRegister(egressMetrics.NfConnctrackLimit)
42+
metrics.Registry.MustRegister(egressMetrics.NfConntrackCount)
43+
metrics.Registry.MustRegister(egressMetrics.NfConntrackLimit)
4244
metrics.Registry.MustRegister(egressMetrics.NfTableMasqueradeBytes)
4345
metrics.Registry.MustRegister(egressMetrics.NfTableMasqueradePackets)
4446
metrics.Registry.MustRegister(egressMetrics.NfTableInvalidBytes)
@@ -71,10 +73,10 @@ func subMain() error {
7173
}
7274
if n4 := n.To4(); n4 != nil {
7375
ipv4 = n4
74-
protocolMap["ipv4"] = struct{}{}
76+
protocolMap[protocolIPv4] = struct{}{}
7577
} else {
7678
ipv6 = n
77-
protocolMap["ipv6"] = struct{}{}
79+
protocolMap[protocolIpv6] = struct{}{}
7880
}
7981
}
8082

@@ -83,7 +85,7 @@ func subMain() error {
8385
protocols = append(protocols, protocol)
8486
}
8587

86-
setupLog.Info("detected local IP addresses", "ipv4", ipv4.String(), "ipv6", ipv6.String())
88+
setupLog.Info("detected local IP addresses", protocolIPv4, ipv4.String(), protocolIpv6, ipv6.String())
8789

8890
timeout := gracefulTimeout
8991
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
@@ -106,13 +108,13 @@ func subMain() error {
106108
return err
107109
}
108110

109-
setupLog.Info("initialize FoU tunnel", "port", config.port, "ipv4", ipv4.String(), "ipv6", ipv6.String())
111+
setupLog.Info("initialize FoU tunnel", "port", config.port, protocolIPv4, ipv4.String(), protocolIpv6, ipv6.String())
110112
ft := founat.NewFoUTunnel(config.port, ipv4, ipv6, nil)
111113
if err := ft.Init(); err != nil {
112114
return err
113115
}
114116

115-
setupLog.Info("initialize Egress", "ipv4", ipv4.String(), "ipv6", ipv6.String())
117+
setupLog.Info("initialize Egress", protocolIPv4, ipv4.String(), protocolIpv6, ipv6.String())
116118
eg := founat.NewEgress("eth0", ipv4, ipv6)
117119
if err := eg.Init(); err != nil {
118120
return err

v2/pkg/metrics/egress.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ const (
2020
)
2121

2222
var (
23-
NfConnctrackCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
23+
NfConntrackCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
2424
Namespace: constants.MetricsNS,
2525
Subsystem: "egress",
2626
Name: "nf_conntrack_entries_count",
2727
Help: "the number of entries in the nf_conntrack table",
2828
}, []string{"namespace", "pod", "egress"})
2929

30-
NfConnctrackLimit = prometheus.NewGaugeVec(prometheus.GaugeOpts{
30+
NfConntrackLimit = prometheus.NewGaugeVec(prometheus.GaugeOpts{
3131
Namespace: constants.MetricsNS,
3232
Subsystem: "egress",
3333
Name: "nf_conntrack_entries_limit",
@@ -71,24 +71,24 @@ type egressCollector struct {
7171
}
7272

7373
type nfTablesPerProtocolMetrics struct {
74-
nfTablesNATPackets prometheus.Gauge
75-
nfTablesNATBytes prometheus.Gauge
76-
nfTablesInvalidPackets prometheus.Gauge
77-
nfTablesInvalidBytes prometheus.Gauge
74+
NATPackets prometheus.Gauge
75+
NATBytes prometheus.Gauge
76+
InvalidPackets prometheus.Gauge
77+
InvalidBytes prometheus.Gauge
7878
}
7979

8080
func newNfTablesPerProtocolMetrics(ns, pod, egress, protocol string) *nfTablesPerProtocolMetrics {
8181
return &nfTablesPerProtocolMetrics{
82-
nfTablesNATPackets: NfTableMasqueradePackets.WithLabelValues(ns, pod, egress, protocol),
83-
nfTablesNATBytes: NfTableMasqueradeBytes.WithLabelValues(ns, pod, egress, protocol),
84-
nfTablesInvalidPackets: NfTableInvalidPackets.WithLabelValues(ns, pod, egress, protocol),
85-
nfTablesInvalidBytes: NfTableInvalidBytes.WithLabelValues(ns, pod, egress, protocol),
82+
NATPackets: NfTableMasqueradePackets.WithLabelValues(ns, pod, egress, protocol),
83+
NATBytes: NfTableMasqueradeBytes.WithLabelValues(ns, pod, egress, protocol),
84+
InvalidPackets: NfTableInvalidPackets.WithLabelValues(ns, pod, egress, protocol),
85+
InvalidBytes: NfTableInvalidBytes.WithLabelValues(ns, pod, egress, protocol),
8686
}
8787
}
8888

8989
func NewEgressCollector(ns, pod, egress string, protocols []string) (Collector, error) {
90-
NfConnctrackCount.Reset()
91-
NfConnctrackLimit.Reset()
90+
NfConntrackCount.Reset()
91+
NfConntrackLimit.Reset()
9292
NfTableMasqueradeBytes.Reset()
9393
NfTableMasqueradePackets.Reset()
9494
NfTableInvalidPackets.Reset()
@@ -106,8 +106,8 @@ func NewEgressCollector(ns, pod, egress string, protocols []string) (Collector,
106106

107107
return &egressCollector{
108108
conn: c,
109-
nfConnctrackCount: NfConnctrackCount.WithLabelValues(ns, pod, egress),
110-
nfConnctrackLimit: NfConnctrackLimit.WithLabelValues(ns, pod, egress),
109+
nfConnctrackCount: NfConntrackCount.WithLabelValues(ns, pod, egress),
110+
nfConnctrackLimit: NfConntrackLimit.WithLabelValues(ns, pod, egress),
111111
perProtocol: perProtocols,
112112
}, nil
113113
}
@@ -135,15 +135,15 @@ func (c *egressCollector) Update(ctx context.Context) error {
135135
if err != nil {
136136
return err
137137
}
138-
nfTablesMetrics.nfTablesNATPackets.Set(float64(natPackets))
139-
nfTablesMetrics.nfTablesNATBytes.Set(float64(natBytes))
138+
nfTablesMetrics.NATPackets.Set(float64(natPackets))
139+
nfTablesMetrics.NATBytes.Set(float64(natBytes))
140140

141141
invalidPackets, invalidBytes, err := c.getNfTablesInvalidCounter(protocol)
142142
if err != nil {
143143
return err
144144
}
145-
nfTablesMetrics.nfTablesInvalidPackets.Set(float64(invalidPackets))
146-
nfTablesMetrics.nfTablesInvalidBytes.Set(float64(invalidBytes))
145+
nfTablesMetrics.InvalidPackets.Set(float64(invalidPackets))
146+
nfTablesMetrics.InvalidBytes.Set(float64(invalidBytes))
147147

148148
}
149149

0 commit comments

Comments
 (0)