Skip to content

Commit 8b907cd

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

File tree

4 files changed

+43
-37
lines changed

4 files changed

+43
-37
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func init() {
3737

3838
// +kubebuilder:scaffold:scheme
3939

40-
metrics.Registry.MustRegister(egressMetrics.NfConnctrackCount)
41-
metrics.Registry.MustRegister(egressMetrics.NfConnctrackLimit)
40+
metrics.Registry.MustRegister(egressMetrics.NfConntrackCount)
41+
metrics.Registry.MustRegister(egressMetrics.NfConntrackLimit)
4242
metrics.Registry.MustRegister(egressMetrics.NfTableMasqueradeBytes)
4343
metrics.Registry.MustRegister(egressMetrics.NfTableMasqueradePackets)
4444
metrics.Registry.MustRegister(egressMetrics.NfTableInvalidBytes)
@@ -71,10 +71,10 @@ func subMain() error {
7171
}
7272
if n4 := n.To4(); n4 != nil {
7373
ipv4 = n4
74-
protocolMap["ipv4"] = struct{}{}
74+
protocolMap[constants.FamilyIPv4] = struct{}{}
7575
} else {
7676
ipv6 = n
77-
protocolMap["ipv6"] = struct{}{}
77+
protocolMap[constants.FamilyIPv6] = struct{}{}
7878
}
7979
}
8080

v2/pkg/constants/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ const MetricsNS = "coil"
9090
const (
9191
DefaultPool = "default"
9292
)
93+
94+
// Layer 3 families
95+
const (
96+
FamilyIPv4 = "ipv4"
97+
FamilyIPv6 = "ipv6"
98+
)

v2/pkg/metrics/egress.go

Lines changed: 29 additions & 29 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",
@@ -64,31 +64,31 @@ var (
6464
)
6565

6666
type egressCollector struct {
67-
conn *nftables.Conn
68-
nfConnctrackCount prometheus.Gauge
69-
nfConnctrackLimit prometheus.Gauge
70-
perProtocol map[string]*nfTablesPerProtocolMetrics
67+
conn *nftables.Conn
68+
nfConntrackCount prometheus.Gauge
69+
nfConntrackLimit prometheus.Gauge
70+
perProtocol map[string]*nfTablesPerProtocolMetrics
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()
@@ -105,10 +105,10 @@ func NewEgressCollector(ns, pod, egress string, protocols []string) (Collector,
105105
}
106106

107107
return &egressCollector{
108-
conn: c,
109-
nfConnctrackCount: NfConnctrackCount.WithLabelValues(ns, pod, egress),
110-
nfConnctrackLimit: NfConnctrackLimit.WithLabelValues(ns, pod, egress),
111-
perProtocol: perProtocols,
108+
conn: c,
109+
nfConntrackCount: NfConntrackCount.WithLabelValues(ns, pod, egress),
110+
nfConntrackLimit: NfConntrackLimit.WithLabelValues(ns, pod, egress),
111+
perProtocol: perProtocols,
112112
}, nil
113113
}
114114

@@ -122,28 +122,28 @@ func (c *egressCollector) Update(ctx context.Context) error {
122122
if err != nil {
123123
return err
124124
}
125-
c.nfConnctrackCount.Set(float64(val))
125+
c.nfConntrackCount.Set(float64(val))
126126

127127
val, err = readUintFromFile(NF_CONNTRACK_LIMIT_PATH)
128128
if err != nil {
129129
return err
130130
}
131-
c.nfConnctrackLimit.Set(float64(val))
131+
c.nfConntrackLimit.Set(float64(val))
132132

133133
for protocol, nfTablesMetrics := range c.perProtocol {
134134
natPackets, natBytes, err := c.getNfTablesNATCounter(protocol)
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

@@ -215,10 +215,10 @@ func readUintFromFile(path string) (uint64, error) {
215215
}
216216

217217
func stringToTableFamily(protocol string) (nftables.TableFamily, error) {
218-
switch strings.ToLower(protocol) {
219-
case "ipv4":
218+
switch protocol {
219+
case constants.FamilyIPv4:
220220
return nftables.TableFamilyIPv4, nil
221-
case "ipv6":
221+
case constants.FamilyIPv6:
222222
return nftables.TableFamilyIPv6, nil
223223
default:
224224
return nftables.TableFamilyUnspecified, fmt.Errorf("unsupported family type: %s", protocol)

0 commit comments

Comments
 (0)