@@ -64,7 +64,7 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte)
64
64
}
65
65
rowKey , colKey := calculateDynamoKeys (userID , now )
66
66
67
- interval := e .reportInterval (rep )
67
+ interval , nodes := e .scanReport (rep )
68
68
// Cache the last-known value of interval for this user, and use
69
69
// it if we didn't find one in this report.
70
70
e .Lock ()
@@ -78,7 +78,7 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte)
78
78
}
79
79
}
80
80
// Billing takes an integer number of seconds, so keep track of the amount lost to rounding
81
- nodeSeconds := interval .Seconds ()* float64 (len ( rep . Host . Nodes ) ) + e .rounding [userID ]
81
+ nodeSeconds := interval .Seconds ()* float64 (nodes ) + e .rounding [userID ]
82
82
rounding := nodeSeconds - math .Floor (nodeSeconds )
83
83
e .rounding [userID ] = rounding
84
84
e .Unlock ()
@@ -151,11 +151,20 @@ func intervalFromCommand(cmd string) string {
151
151
return ""
152
152
}
153
153
154
- // reportInterval tries to find the custom report interval of this report. If
155
- // it is malformed, or not set, it returns zero.
156
- func (e * BillingEmitter ) reportInterval (r report.Report ) time.Duration {
154
+ // scanReport counts the nodes tries to find any custom report interval
155
+ // of this report. If it is malformed, or not set, it returns zero.
156
+ func (e * BillingEmitter ) scanReport (r report.Report ) (time.Duration , int ) {
157
+ nHosts := 0
158
+ // We scan the host nodes looking for ones reported by a per-node probe;
159
+ // the Kubernetes cluster probe also makes host nodes but they only have a few fields set
160
+ for _ , h := range r .Host .Nodes {
161
+ // Relying here on Uptime being something that changes in each report, hence will be in a delta report
162
+ if _ , ok := h .Latest .Lookup (report .Uptime ); ok {
163
+ nHosts ++
164
+ }
165
+ }
157
166
if r .Window != 0 {
158
- return r .Window
167
+ return r .Window , nHosts
159
168
}
160
169
var inter string
161
170
for _ , c := range r .Container .Nodes {
@@ -175,13 +184,13 @@ func (e *BillingEmitter) reportInterval(r report.Report) time.Duration {
175
184
}
176
185
}
177
186
if inter == "" {
178
- return 0
187
+ return 0 , nHosts
179
188
}
180
189
d , err := time .ParseDuration (inter )
181
190
if err != nil {
182
- return 0
191
+ return 0 , nHosts
183
192
}
184
- return d
193
+ return d , nHosts
185
194
}
186
195
187
196
// Tries to determine if this report came from a host running Weave Net
0 commit comments