Skip to content

Commit

Permalink
Add BPF mode in clustertype
Browse files Browse the repository at this point in the history
  • Loading branch information
sridhartigera committed Apr 17, 2020
1 parent 5df0199 commit 7e0c6c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 8 additions & 4 deletions usagerep/usagerep.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ func (u *UsageReporter) PeriodicallyReportUsage(ctx context.Context) {

doReport := func() {
alpEnabled := (config["PolicySyncPathPrefix"] != "")
u.reportUsage(config["ClusterGUID"], config["ClusterType"], config["CalicoVersion"], alpEnabled, stats)
bpfEnabled := (config["BPFEnabled"] == "true")
u.reportUsage(config["ClusterGUID"], config["ClusterType"], config["CalicoVersion"], alpEnabled, bpfEnabled, stats)
}

var ticker *jitter.Ticker
Expand Down Expand Up @@ -149,8 +150,8 @@ func (u *UsageReporter) calculateInitialDelay(numHosts int) time.Duration {
return initialDelay
}

func (u *UsageReporter) reportUsage(clusterGUID, clusterType, calicoVersion string, alpEnabled bool, stats calc.StatsUpdate) {
fullURL := u.calculateURL(clusterGUID, clusterType, calicoVersion, alpEnabled, stats)
func (u *UsageReporter) reportUsage(clusterGUID, clusterType, calicoVersion string, alpEnabled bool, bpfEnabled bool, stats calc.StatsUpdate) {
fullURL := u.calculateURL(clusterGUID, clusterType, calicoVersion, alpEnabled, bpfEnabled, stats)
resp, err := u.httpClient.Get(fullURL)
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
Expand All @@ -172,7 +173,7 @@ func (u *UsageReporter) reportUsage(clusterGUID, clusterType, calicoVersion stri
}
}

func (u *UsageReporter) calculateURL(clusterGUID, clusterType, calicoVersion string, alpEnabled bool, stats calc.StatsUpdate) string {
func (u *UsageReporter) calculateURL(clusterGUID, clusterType, calicoVersion string, alpEnabled bool, bpfEnabled bool, stats calc.StatsUpdate) string {
var kubernetesVersion string

if clusterType == "" {
Expand All @@ -189,6 +190,9 @@ func (u *UsageReporter) calculateURL(clusterGUID, clusterType, calicoVersion str
if clusterGUID == "" {
clusterGUID = "baddecaf"
}
if bpfEnabled {
clusterType = clusterType + ",bpf"
}
log.WithFields(log.Fields{
"clusterGUID": clusterGUID,
"clusterType": clusterType,
Expand Down
9 changes: 5 additions & 4 deletions usagerep/usagerep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// 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 usagerep

import (
Expand Down Expand Up @@ -88,6 +87,7 @@ var _ = Describe("UsageReporter with mocked URL and short interval", func() {
"ClusterGUID": "someguid",
"ClusterType": "openstack,k8s,kdd",
"CalicoVersion": "v2.6.3",
"BPFEnabled": "false",
}
}

Expand Down Expand Up @@ -176,6 +176,7 @@ var _ = Describe("UsageReporter with mocked URL and short interval", func() {
"ClusterType": "openstack,k8s,kdd,typha",
"CalicoVersion": "v3.0.0",
"PolicySyncPathPrefix": "/var/run/nodeagent",
"BPFEnabled": "true",
}
})

Expand All @@ -190,7 +191,7 @@ var _ = Describe("UsageReporter with mocked URL and short interval", func() {
q := url.Query()
Expect(q).To(HaveLen(expectedNumberOfURLParams), "unexpected number of URL parameters")
Expect(q.Get("guid")).To(Equal("someguid2"))
Expect(q.Get("type")).To(Equal("openstack,k8s,kdd,typha"))
Expect(q.Get("type")).To(Equal("openstack,k8s,kdd,typha,bpf"))
Expect(q.Get("cal_ver")).To(Equal("v3.0.0"))
Expect(q.Get("k8s_ver")).To(Equal("v1.17.0"))
Expect(q.Get("alp")).To(Equal("true"))
Expand Down Expand Up @@ -238,7 +239,7 @@ var _ = Describe("UsageReporter with default URL", func() {
})

It("should calculate correct URL mainline", func() {
rawURL := u.calculateURL("theguid", "atype", "testVer", true, calc.StatsUpdate{
rawURL := u.calculateURL("theguid", "atype", "testVer", true, false, calc.StatsUpdate{
NumHostEndpoints: 123,
NumWorkloadEndpoints: 234,
NumHosts: 10,
Expand All @@ -263,7 +264,7 @@ var _ = Describe("UsageReporter with default URL", func() {
Expect(url.Path).To(Equal("/UsageCheck/calicoVersionCheck"))
})
It("should default cluster type, GUID, and Calico Version", func() {
rawURL := u.calculateURL("", "", "", false, calc.StatsUpdate{
rawURL := u.calculateURL("", "", "", false, false, calc.StatsUpdate{
NumHostEndpoints: 123,
NumWorkloadEndpoints: 234,
NumHosts: 10,
Expand Down

0 comments on commit 7e0c6c4

Please sign in to comment.