Skip to content

add support for other projects for external metrics#212

Merged
kawych merged 6 commits intoGoogleCloudPlatform:masterfrom
dronedeploy:stackdriver-adapter-multi-project
Oct 12, 2018
Merged

add support for other projects for external metrics#212
kawych merged 6 commits intoGoogleCloudPlatform:masterfrom
dronedeploy:stackdriver-adapter-multi-project

Conversation

@astropuffin
Copy link
Contributor

@astropuffin astropuffin commented Oct 5, 2018

Addresses #205

I tried to keep my changes as minimal as possible as I don't really have the bandwidth or expertise to do a large refactor. This has been tested in my environment to maintain existing functionality, as well as access to metrics in other projects. Adding scope was necessary to allow a service account to work, rather than GCE creds.

I would be happy to contribute documentation if this PR's code is deemed mergable.

Example spec:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: dummy
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1beta1
    kind: Deployment
    name: dummy
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - external:
      metricName: pubsub.googleapis.com|subscription|num_undelivered_messages
      metricSelector:
        matchLabels:
          resource.labels.subscription_id: super-awesome-sub
          resource.labels.project_id: other-project
      targetAverageValue: "2"
    type: External

Note: Access to other projects requires running the stackdriver adapter with a service account (recommended), or adding permissions to the default GCE creds (not advised).

@kawych kawych self-requested a review October 5, 2018 11:29
@kawych kawych self-assigned this Oct 5, 2018
func (t *Translator) GetExternalMetricProject(metricSelector labels.Selector) (string, error) {
requirements, _ := metricSelector.Requirements()
for _, req := range requirements {
if req.Key() == "resource.labels.project_id" {
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure that req.Operator() is selection.Equals (or selection.DoubleEquals), otherwise an error should be returned.

@kawych
Copy link
Member

kawych commented Oct 5, 2018

Thanks for contribution! I have a small comment, but LGTM otherwise. Please update the documentation to reflect this.

@astropuffin
Copy link
Contributor Author

astropuffin commented Oct 8, 2018

@kawych Added documentation. Let me know if it needs anything else, whether stylistic or content. I followed the existing examples docs.

@kawych
Copy link
Member

kawych commented Oct 8, 2018

Thanks. Can you file a separate PR for the documentation? Sorry for not being clear with that, I want to submit it only after we do a next release of the adapter.

@astropuffin
Copy link
Contributor Author

@kawych done. See #213

@kawych
Copy link
Member

kawych commented Oct 12, 2018

LGTM

@kawych kawych merged commit d57ef49 into GoogleCloudPlatform:master Oct 12, 2018
@astropuffin astropuffin deleted the stackdriver-adapter-multi-project branch October 12, 2018 17:04
@bjorndv
Copy link

bjorndv commented Dec 19, 2018

I've noticed that the last release is from 18 June (custom-metrics-stackdriver-adapter v0.8.0). Are there any plans to roll out a new release soon? I could really use this feature.

@kawych
Copy link
Member

kawych commented Dec 28, 2018

I've started a release of the new version. Should be available in several days.

@bjorndv
Copy link

bjorndv commented Jan 24, 2019

Any update on the release? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants