From 69935b305ab3552bc8626c8f81a802ec559a31e4 Mon Sep 17 00:00:00 2001 From: Vishwanath Date: Mon, 1 Apr 2019 11:09:27 -0700 Subject: [PATCH] Vishwa/resourcecentric (#208) * resourceid fix (for AKS only) * fix name --- source/code/go/src/plugins/oms.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/code/go/src/plugins/oms.go b/source/code/go/src/plugins/oms.go index 36cf20273..a1ca3d6ee 100644 --- a/source/code/go/src/plugins/oms.go +++ b/source/code/go/src/plugins/oms.go @@ -44,6 +44,10 @@ var ( Computer string // WorkspaceID log analytics workspace id WorkspaceID string + // ResourceID for resource-centric log analytics data + ResourceID string + // Resource-centric flag (will be true if we determine if above RseourceID is non-empty - default is false) + ResourceCentric bool ) var ( @@ -294,6 +298,10 @@ func PostDataHelper(tailPluginRecords []map[interface{}]interface{}) int { } req, _ := http.NewRequest("POST", OMSEndpoint, bytes.NewBuffer(marshalled)) req.Header.Set("Content-Type", "application/json") + //expensive to do string len for every request, so use a flag + if ResourceCentric == true { + req.Header.Set("x-ms-AzureResourceId", ResourceID) + } resp, err := HTTPClient.Do(req) elapsed := time.Since(start) @@ -377,6 +385,11 @@ func InitializePlugin(pluginConfPath string, agentVersion string) { } OMSEndpoint = omsadminConf["OMS_ENDPOINT"] WorkspaceID = omsadminConf["WORKSPACE_ID"] + ResourceID = os.Getenv("customResourceId") + if len(ResourceID) > 0 { + ResourceCentric = true + Log("OMS ResourceId=%s",ResourceID) + } Log("OMSEndpoint %s", OMSEndpoint) // Initialize image,name map refresh ticker