Skip to content

Commit 0cf6b37

Browse files
committed
cleanup
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent ce62b68 commit 0cf6b37

File tree

5 files changed

+11
-43
lines changed

5 files changed

+11
-43
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Global metrics
5252
| `azure_loganalytics_query_time` | Summary metric about query execution time (incl. all subqueries) |
5353
| `azure_loganalytics_query_results` | Number of results from query |
5454
| `azure_loganalytics_query_requests` | Count of requests (eg paged subqueries) per query |
55-
| `azure_loganalytics_ratelimit` | Current rate limit value from the Azure loganalytics API |
5655

5756

5857
Example

config/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type (
1616

1717
// azure
1818
Azure struct {
19-
Environment *string `long:"azure-environment" env:"AZURE_ENVIRONMENT" description:"Azure environment name" default:"AZUREPUBLICCLOUD"`
19+
Environment *string `long:"azure-environment" env:"AZURE_ENVIRONMENT" description:"Azure environment name" default:"AZUREPUBLICCLOUD"`
2020
}
2121

2222
Loganalytics struct {

global-metrics.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var (
66
prometheusQueryTime *prometheus.SummaryVec
77
prometheusQueryResults *prometheus.GaugeVec
88
prometheusQueryRequests *prometheus.CounterVec
9-
prometheusRateLimit *prometheus.GaugeVec
109
)
1110

1211
func initGlobalMetrics() {
@@ -46,13 +45,4 @@ func initGlobalMetrics() {
4645
},
4746
)
4847
prometheus.MustRegister(prometheusQueryRequests)
49-
50-
prometheusRateLimit = prometheus.NewGaugeVec(
51-
prometheus.GaugeOpts{
52-
Name: "azure_loganalytics_ratelimit",
53-
Help: "Azure loganalytics ratelimit",
54-
},
55-
[]string{},
56-
)
57-
prometheus.MustRegister(prometheusRateLimit)
5848
}

main.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
65
"github.com/Azure/go-autorest/autorest"
76
"github.com/Azure/go-autorest/autorest/azure"
87
"github.com/Azure/go-autorest/autorest/azure/auth"
@@ -28,12 +27,10 @@ var (
2827
argparser *flags.Parser
2928
opts config.Opts
3029

31-
Config kusto.Config
30+
Config kusto.Config
3231

33-
AzureAuthorizer autorest.Authorizer
34-
OpInsightsAuthorizer autorest.Authorizer
35-
AzureSubscriptions []subscriptions.Subscription
36-
AzureEnvironment azure.Environment
32+
OpInsightsAuthorizer autorest.Authorizer
33+
AzureEnvironment azure.Environment
3734

3835
metricCache *cache.Cache
3936

@@ -121,12 +118,6 @@ func readConfig() {
121118
func initAzureConnection() {
122119
var err error
123120

124-
// setup azure authorizer
125-
AzureAuthorizer, err = auth.NewAuthorizerFromEnvironment()
126-
if err != nil {
127-
log.Panic(err)
128-
}
129-
130121
AzureEnvironment, err = azure.EnvironmentFromName(*opts.Azure.Environment)
131122
if err != nil {
132123
log.Panic(err)

probe.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import (
1212
log "github.com/sirupsen/logrus"
1313
"github.com/webdevops/azure-resourcegraph-exporter/kusto"
1414
"net/http"
15-
"strconv"
1615
"time"
1716
)
1817

1918
const (
20-
RESOURCEGRAPH_QUERY_OPTIONS_TOP = 1000
19+
OPINSIGHTS_URL_SUFFIX = "/v1"
2120
)
2221

2322
func handleProbeRequest(w http.ResponseWriter, r *http.Request) {
@@ -44,14 +43,8 @@ func handleProbeRequest(w http.ResponseWriter, r *http.Request) {
4443

4544
ctx := context.Background()
4645

47-
defaultSubscriptions := []string{}
48-
for _, subscription := range AzureSubscriptions {
49-
defaultSubscriptions = append(defaultSubscriptions, *subscription.SubscriptionID)
50-
}
51-
52-
// Create and authorize a ResourceGraph client
53-
// queryClient := operationalinsights.NewQueryClientWithBaseURI(AzureEnvironment.ResourceIdentifiers.OperationalInsights + "/v1/")
54-
queryClient := operationalinsights.NewQueryClient()
46+
// Create and authorize a operationalinsights client
47+
queryClient := operationalinsights.NewQueryClientWithBaseURI(AzureEnvironment.ResourceIdentifiers.OperationalInsights + OPINSIGHTS_URL_SUFFIX)
5548
queryClient.Authorizer = OpInsightsAuthorizer
5649
queryClient.ResponseInspector = respondDecorator()
5750

@@ -83,7 +76,6 @@ func handleProbeRequest(w http.ResponseWriter, r *http.Request) {
8376
}
8477
startTime := time.Now()
8578

86-
8779
contextLogger := probeLogger.WithField("metric", queryConfig.Metric)
8880

8981
if queryConfig.Timespan == nil {
@@ -100,8 +92,8 @@ func handleProbeRequest(w http.ResponseWriter, r *http.Request) {
10092
// Set options
10193
workspaces := []string{}
10294
queryBody := operationalinsights.QueryBody{
103-
Query: &queryConfig.Query,
104-
Timespan: queryConfig.Timespan,
95+
Query: &queryConfig.Query,
96+
Timespan: queryConfig.Timespan,
10597
Workspaces: &workspaces,
10698
}
10799

@@ -115,7 +107,7 @@ func handleProbeRequest(w http.ResponseWriter, r *http.Request) {
115107
contextLogger.Debug("parsing result")
116108
resultTables := *results.Tables
117109

118-
if resultTables != nil && len(resultTables) == 1 {
110+
if len(resultTables) == 1 {
119111
for _, v := range *resultTables[0].Rows {
120112
resultTotalRecords++
121113
resultRow := map[string]interface{}{}
@@ -126,7 +118,7 @@ func handleProbeRequest(w http.ResponseWriter, r *http.Request) {
126118

127119
for metricName, metric := range kusto.BuildPrometheusMetricList(queryConfig.Metric, queryConfig.MetricConfig, resultRow) {
128120
// inject workspaceId
129-
for num, _ := range metric {
121+
for num := range metric {
130122
metric[num].Labels["workspaceId"] = workspaceId
131123
}
132124

@@ -188,10 +180,6 @@ func handleProbeRequest(w http.ResponseWriter, r *http.Request) {
188180
func respondDecorator() autorest.RespondDecorator {
189181
return func(p autorest.Responder) autorest.Responder {
190182
return autorest.ResponderFunc(func(r *http.Response) error {
191-
ratelimit := r.Header.Get("x-ms-user-quota-remaining")
192-
if v, err := strconv.ParseInt(ratelimit, 10, 64); err == nil {
193-
prometheusRateLimit.WithLabelValues().Set(float64(v))
194-
}
195183
return nil
196184
})
197185
}

0 commit comments

Comments
 (0)