Skip to content

Commit cf8c57b

Browse files
committed
add optional flag for workspace discovery
1 parent 875e6dd commit cf8c57b

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,20 @@ uses Azure service discovery to find all workspaces in one or multiple subscript
8585
| `filter` | | no | no | Advanced filter for `resource \| {filter} \| project id, customerId=properties.customerId` ResoruceGraph query (available with `23.6.0`) |
8686
| `cache` | | no | no | Use of internal metrics caching (time.Duration) |
8787
| `parallel` | `$LOGANALYTICS_PARALLEL` | no | no | Number (int) of how many workspaces can be queried at the same time |
88+
| `optional` | `false` | no | no | Do not fail, if service discovery did not find any workspaces |
8889

8990
## Global metrics
9091

9192
available on `/metrics`
9293

93-
| Metric | Description |
94-
|---------------------------------------------|--------------------------------------------------------------------------------|
95-
| `azure_loganalytics_status` | Status if query was successfull (per workspace, module, metric) |
96-
| `azure_loganalytics_last_query_successfull` | Timestamp of last successfull query (per workspace, module, metric) |
97-
| `azure_loganalytics_query_time` | Summary metric about query execution time (incl. all subqueries) |
98-
| `azure_loganalytics_query_results` | Number of results from query |
99-
| `azure_loganalytics_query_requests` | Count of requests (eg paged subqueries) per query |
94+
| Metric | Description |
95+
|---------------------------------------------|---------------------------------------------------------------------|
96+
| `azure_loganalytics_status` | Status if query was successfull (per workspace, module, metric) |
97+
| `azure_loganalytics_last_query_successfull` | Timestamp of last successfull query (per workspace, module, metric) |
98+
| `azure_loganalytics_query_time` | Summary metric about query execution time (incl. all subqueries) |
99+
| `azure_loganalytics_query_results` | Number of results from query |
100+
| `azure_loganalytics_query_requests` | Count of requests (eg paged subqueries) per query |
101+
| `azure_loganalytics_workspace_query_count` | Count of discovered workspaces per module |
100102

101103
### AzureTracing metrics
102104

loganalytics/global-metrics.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var (
88
prometheusQueryRequests *prometheus.CounterVec
99
prometheusQueryStatus *prometheus.GaugeVec
1010
prometheusQueryLastSuccessfull *prometheus.GaugeVec
11+
prometheusQueryWorkspaceCount *prometheus.GaugeVec
1112
)
1213

1314
func InitGlobalMetrics() {
@@ -72,5 +73,14 @@ func InitGlobalMetrics() {
7273
"metric",
7374
},
7475
)
75-
prometheus.MustRegister(prometheusQueryLastSuccessfull)
76+
prometheusQueryWorkspaceCount = prometheus.NewGaugeVec(
77+
prometheus.GaugeOpts{
78+
Name: "azure_loganalytics_workspace_query_count",
79+
Help: "Azure loganalytics workspace query count",
80+
},
81+
[]string{
82+
"module",
83+
},
84+
)
85+
prometheus.MustRegister(prometheusQueryWorkspaceCount)
7686
}

loganalytics/prober.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type (
5454

5555
config struct {
5656
moduleName string
57+
optional bool
5758
cacheEnabled bool
5859
cacheDuration *time.Duration
5960
cacheKey *string
@@ -100,6 +101,7 @@ func NewLogAnalyticsProber(logger *zap.SugaredLogger, w http.ResponseWriter, r *
100101

101102
func (p *LogAnalyticsProber) Init() {
102103
p.config.moduleName = p.request.URL.Query().Get("module")
104+
p.config.optional = p.request.URL.Query().Get("optional") == "true"
103105

104106
p.logger = p.logger.With(zap.String("module", p.config.moduleName))
105107

@@ -176,6 +178,12 @@ func (p *LogAnalyticsProber) Run() {
176178
p.ServiceDiscovery.ServiceDiscovery()
177179
}
178180

181+
prometheusQueryWorkspaceCount.With(prometheus.Labels{"module": p.config.moduleName}).Set(float64(len(p.workspaceList)))
182+
183+
if p.config.optional && len(p.workspaceList) == 0 {
184+
return
185+
}
186+
179187
err := p.executeQueries()
180188
if err != nil {
181189
p.logger.With(zap.String("request", p.request.RequestURI)).Error(err)

0 commit comments

Comments
 (0)