Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

cmd/bosun: Azure Monitor Datasource - #2283

Merged
kylebrandt merged 5 commits into
masterfrom
ads
Aug 1, 2018
Merged

kylebrandt merged 5 commits into
masterfrom
ads

Conversation

@kylebrandt

Copy link
Copy Markdown
Member

No description provided.

@kylebrandt
kylebrandt force-pushed the ads branch 2 times, most recently from e22f47c to 1fc3f64 Compare July 31, 2018 12:24
@kylebrandt

kylebrandt commented Jul 31, 2018

Copy link
Copy Markdown
Member Author

For review except the metric metadata function which can be ignored for now. Also will vendor later. cc @mhenderson-so . Note: the azure datasource commit by itself has some cache edits by accident and doesn't build, so I will probably just squash all this into one when time ready for master. (fixed in rebase and force push)

@kylebrandt
kylebrandt requested a review from captncraig July 31, 2018 12:50
@kylebrandt kylebrandt changed the title cmd/bosun: (WIP) Azure Monitor Datasource cmd/bosun: Azure Monitor Datasource Jul 31, 2018
Comment thread cmd/bosun/conf/system.go Outdated
DebugResponse bool
}

// Valid returns if the configuration for the AzureMonitor

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix comment

Comment thread cmd/bosun/conf/system.go
return allClients
}

func azureLogRequest() autorest.PrepareDecorator {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment this function and the following, add comment to attribute source of readme from the go azure sdk

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these even required long term?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they hurt, and since the documentation is marking the experimental for now they could be handy. I would probably be better if more datasources had this I think

Comment thread cmd/bosun/conf/system.go Outdated
if err != nil {
slog.Warningf("failure to dump azure request: %v", err)
}
dump, _ := httputil.DumpRequestOut(r, true)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check + log err

Comment thread cmd/bosun/conf/system.go Outdated
if err != nil {
slog.Warningf("failure to dump azure request: %v", err)
}
dump, _ := httputil.DumpResponse(r, true)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check + log err

Comment thread cmd/bosun/expr/azure.go Outdated
},
}

// Tag function for the "az" expression function

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: azTags is

Comment thread cmd/bosun/expr/azure.go Outdated
return azureTags(args[2])
}

// Tag function for the "azmulti" expression function

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: azMultiTags is

Comment thread cmd/bosun/expr/azure.go Outdated

// azureTags adds tags for the csv argument along with the "name" and "rsg" tags
func azureTags(arg parse.Node) (parse.Tags, error) {
tags := parse.Tags{"name": struct{}{}, "rsg": struct{}{}}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make name and rsg constants and change in all places where referenced

Comment thread cmd/bosun/expr/azure.go

const azTimeFmt = "2006-01-02T15:04:05"

func azResourceURI(subscription, resourceGrp, Namespace, Resource string) string {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment func

Comment thread cmd/bosun/expr/azure.go
return
}

// AzureQuery queries an Azure monitor metric for the given resource and returns a series set tagged by

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finish this func comment

Comment thread cmd/bosun/expr/azure.go Outdated
// Verify prefix is a defined resource and fetch the collection of clients
cc, clientFound := e.Backends.AzureMonitor[prefix]
if !clientFound {
return r, fmt.Errorf("azure client with name %v not defined", prefix)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... "%v" ...

Comment thread cmd/bosun/expr/azure.go Outdated
st := e.now.Add(time.Duration(-sd)).Format(azTimeFmt)
en := e.now.Add(time.Duration(-ed)).Format(azTimeFmt)

// Set Dimensions (tag) keys for metrics that support them by building a filter

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread cmd/bosun/expr/azure.go Outdated
tg = azureIntervalToTimegrain(interval)
}

// Set azure aggregation method

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Find various "azure" comments and replace with "Azure" (casing)

Comment thread cmd/bosun/expr/azure.go
if err != nil {
slog.Errorf("failure to parse remaning reads from azure response")
} else {
collect.Sample("azure.remaining_reads", opentsdb.TagSet{"prefix": prefix}, float64(readsRemaining))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment explaining why this is sampled

Comment thread cmd/bosun/expr/expr.go Outdated
// collectCache is a helper function for collecting metrics on
// the expression cache
func collectCacheHit(cacheName, qType string, hit bool) {
tags := opentsdb.TagSet{"query_type": qType, "name": cacheName}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add metadata for these metrics

Comment thread cmd/bosun/expr/azure.go Outdated
}
series := make(Series)
tags := make(opentsdb.TagSet)
tags["rsg"] = rsg

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref constant here

Comment thread cmd/bosun/expr/azure.go
}
}
for _, mValue := range *dataContainer.Data {
exValue := azureExtractMetricValue(&mValue, aggLong)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment

Comment thread cmd/bosun/expr/azure.go
for res := range resCh {
queryResults = append(queryResults, res)
}
// Merge the query results into a single seriesSet

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip merge if length of set is not gt than 1

Comment thread cmd/bosun/expr/azure.go
// or tags associated with that resource
func AzureFilterResources(e *State, T miniprofiler.Timer, resources AzureResources, filter string) (r *Results, err error) {
r = new(Results)
bqf, err := boolq.Parse(filter)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment

Comment thread cmd/bosun/expr/azure.go
if len(sp) != 2 {
return false, fmt.Errorf("bad filter, filter must be in k:v format, got %v", filter)
}
key := strings.ToLower(sp[0]) // Make key case insensitive

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note case insensitivity in expression docs

Comment thread cmd/bosun/expr/azure.go Outdated
key := strings.ToLower(sp[0]) // Make key case insensitive
value := sp[1]
switch key {
case "name":

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consts again for name, rsg

Comment thread cmd/bosun/expr/azure.go Outdated
if re.MatchString(ar.Name) {
return true, nil
}
case "rsg", "resourcegroup":

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove "resourcegroup" alias, no real point, update expr docs to reflect

Comment thread cmd/bosun/expr/azure.go
case string(insights.Maximum):
v = mv.Maximum
case string(insights.Total):
v = mv.Total

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add missing None aggregation

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nm, None isn't a field in the sdk

Comment thread cmd/bosun/expr/azure.go
return string(insights.Maximum), nil
case "total":
return string(insights.Total), nil
case "count":

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add missing none aggregation here as well

@captncraig captncraig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems pretty good to me. Just finish out todos and comments.

Comment thread cmd/bosun/conf/system.go Outdated
b.Influx = sc.InfluxConf.URL != ""
b.Elastic = len(sc.ElasticConf["default"].Hosts) != 0
b.Annotate = len(sc.AnnotateConf.Hosts) != 0
b.AzureMonitor = sc.AzureMonitorConf["default"].ClientId != ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a weak thing to check. Are they required to have a "default"? Is ClientID required? (assume thats a credential of some kind?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed will make something better, this is left from my first pass

Comment thread cmd/bosun/conf/system.go
clients.MetricsClient = insights.NewMetricsClient(conf.SubscriptionId)
clients.MetricDefinitionsClient = insights.NewMetricDefinitionsClient(conf.SubscriptionId)
clients.ResourcesClient = resources.NewClient(conf.SubscriptionId)
if conf.DebugRequest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these debug things long term? I'd probably prefer not having a million different config options if we can avoid it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two options. Could help with people debugging issues, in particular since I saw what I think is a bug in the SDK about error being missed.

Comment thread cmd/bosun/conf/system.go Outdated
if err != nil {
// Should not hit this since we check for authorizer errors in Validation
// This is checked before because this method is not called until the an expression is called
slog.Fatal("Azure conf: ", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fatal feels wrong here. Does this method get invoked every time an expression runs? If azure is down intermittently, could this crash bosun?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this actually make any API calls and is just a validity thing. So it should be caught by Valid() method, but added this here in case I'm wrong.

Comment thread cmd/bosun/conf/system.go
return allClients
}

func azureLogRequest() autorest.PrepareDecorator {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these even required long term?

Comment thread cmd/bosun/expr/azure.go
F: AzureMultiQuery,
PrefixEnabled: true,
},
"azmd": { // TODO Finish and document this func

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo

Comment thread cmd/bosun/expr/azure.go
F: AzureResourcesByType,
PrefixEnabled: true,
},
"azrf": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

azrf or azfr? Inner function is "FilterResources", so maybe azfr matches better? I kinda hate short names.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think like azrf because it shares the azr prefix with azrt

Comment thread cmd/bosun/expr/azure.go
}

// AzureMetricDefinitions fetches metric information for a specific resource and metric tuple
// TODO make this return and not fmt.Printf

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo

Comment thread cmd/bosun/expr/azure.go
return
}
}
st := e.now.Add(time.Duration(-sd)).Format(azTimeFmt)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"startTime" and "endTime" would not be unreasonable names.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is done I want to go back and make a method on the State that does since we use it all the time.

@kylebrandt
kylebrandt force-pushed the ads branch 2 times, most recently from 7919b3d to 4dce241 Compare August 1, 2018 14:56
this includes an incomplete azure metadata function with TODOs to be
completed in a future commit.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants