From 7e0c6c4d1860dd138922dea19908e7f00a34950f Mon Sep 17 00:00:00 2001 From: sridhar mahadevan Date: Fri, 17 Apr 2020 18:18:58 +0530 Subject: [PATCH] Add BPF mode in clustertype --- usagerep/usagerep.go | 12 ++++++++---- usagerep/usagerep_test.go | 9 +++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/usagerep/usagerep.go b/usagerep/usagerep.go index 6ff831cd8c..257a09e8af 100644 --- a/usagerep/usagerep.go +++ b/usagerep/usagerep.go @@ -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 @@ -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() @@ -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 == "" { @@ -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, diff --git a/usagerep/usagerep_test.go b/usagerep/usagerep_test.go index a0063e5af9..a5fe9847c3 100644 --- a/usagerep/usagerep_test.go +++ b/usagerep/usagerep_test.go @@ -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 ( @@ -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", } } @@ -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", } }) @@ -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")) @@ -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, @@ -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,