Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Add implicit instance resource mapping.#55

Merged
igorpeshansky merged 5 commits intomasterfrom
igorp-instance-resource
Feb 23, 2018
Merged

Add implicit instance resource mapping.#55
igorpeshansky merged 5 commits intomasterfrom
igorp-instance-resource

Conversation

@igorpeshansky
Copy link
Copy Markdown
Contributor

Also factor out an InstanceUpdater that polls the instance resource and add more configuration options.

Copy link
Copy Markdown
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

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

Looks reasonable, however, I'm confused by the merging of technical debt fixes with the overall goal of the PR.

Comment thread src/configuration.cc Outdated
8*1024*1024;
constexpr const char kMetadataIngestionDefaultRawContentVersion[] = "0.1";
constexpr const int kInstanceUpdaterDefaultIntervalSeconds = 60*60;
constexpr const char kDefaultInstanceResourceType[] = "";
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.

Should this be blank?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Blank means "get it from the environment".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just added a comment to that effect.

Comment thread src/configuration.cc
"/resourceMetadata:batchUpdate";
constexpr const int kMetadataIngestionDefaultRequestSizeLimitBytes =
8*1024*1024;
constexpr const char kMetadataIngestionDefaultRawContentVersion[] = "0.1";
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 was previously only used for Kubernetes, is it reasonable to say that the agent will evolve all resources linearly with a single version? Is it possible for the raw content to change over time at different rates over different resource types? I'm not sure how this contract works with the API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is the version of the envelope schema for the metadata ingestion API. The next PR will use it for Docker container resources as well.

Comment thread src/docker.cc Outdated
});

const json::Object* container_desc = parsed_metadata->As<json::Object>();
const json::Object* container_desc = raw_docker->As<json::Object>();
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.

I'm not sure why these changes are being bundled in here. This looks like a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is basically drive-by cleanup. I'm happy to move these into the next PR that deals specifically with Docker.
Done.

Copy link
Copy Markdown
Contributor Author

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

Thanks for the review. PTAL.

Comment thread src/configuration.cc Outdated
8*1024*1024;
constexpr const char kMetadataIngestionDefaultRawContentVersion[] = "0.1";
constexpr const int kInstanceUpdaterDefaultIntervalSeconds = 60*60;
constexpr const char kDefaultInstanceResourceType[] = "";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Blank means "get it from the environment".

Comment thread src/configuration.cc
"/resourceMetadata:batchUpdate";
constexpr const int kMetadataIngestionDefaultRequestSizeLimitBytes =
8*1024*1024;
constexpr const char kMetadataIngestionDefaultRawContentVersion[] = "0.1";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is the version of the envelope schema for the metadata ingestion API. The next PR will use it for Docker container resources as well.

Comment thread src/docker.cc Outdated
});

const json::Object* container_desc = parsed_metadata->As<json::Object>();
const json::Object* container_desc = raw_docker->As<json::Object>();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is basically drive-by cleanup. I'm happy to move these into the next PR that deals specifically with Docker.
Done.

Comment thread src/instance.cc Outdated
@@ -0,0 +1,63 @@
/*
* Copyright 2017 Google Inc.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2018?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes, time flies... 😄 Done.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤣

Comment thread src/configuration.cc
constexpr const int kMetadataIngestionDefaultRequestSizeLimitBytes =
8*1024*1024;
constexpr const char kMetadataIngestionDefaultRawContentVersion[] = "0.1";
constexpr const int kInstanceUpdaterDefaultIntervalSeconds = 60*60;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

An interval of 1 hour? Because GCE instance don't get updated often?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct. Actually, the bits we care about (the resource id) never change. I thought of actually making it 24 hours, or even larger, because we really only need the initial load on startup. Finally settled on 1 hour, for no good reason.

If we choose to actually send mutable instance metadata, including tags, etc, we would poll this more often (e.g., once a minute), just like any other resource.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Makes sense. Thanks for the clarification.

Comment thread src/environment.cc
} else {
// Default to a GCE instance.
// TODO: Detect other resources.
instance_resource_type_ = kGceInstanceResourceType;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A question not directly related to this PR:
For other resources to be detected, is k8s_node one of them, assuming the metadata agent runs on the same node?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this is the underlying instance resource. "Other resources" in this case would be "aws_ec2_instance", for example. Adjusted the comment to make this clearer.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ah, right. Thanks for adding the comment!

Copy link
Copy Markdown
Contributor Author

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL.

Comment thread src/environment.cc
} else {
// Default to a GCE instance.
// TODO: Detect other resources.
instance_resource_type_ = kGceInstanceResourceType;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this is the underlying instance resource. "Other resources" in this case would be "aws_ec2_instance", for example. Adjusted the comment to make this clearer.

Comment thread src/instance.cc Outdated
@@ -0,0 +1,63 @@
/*
* Copyright 2017 Google Inc.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes, time flies... 😄 Done.

Comment thread src/configuration.cc
constexpr const int kMetadataIngestionDefaultRequestSizeLimitBytes =
8*1024*1024;
constexpr const char kMetadataIngestionDefaultRawContentVersion[] = "0.1";
constexpr const int kInstanceUpdaterDefaultIntervalSeconds = 60*60;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct. Actually, the bits we care about (the resource id) never change. I thought of actually making it 24 hours, or even larger, because we really only need the initial load on startup. Finally settled on 1 hour, for no good reason.

If we choose to actually send mutable instance metadata, including tags, etc, we would poll this more often (e.g., once a minute), just like any other resource.

Copy link
Copy Markdown
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread src/instance.h
#ifndef INSTANCE_H_
#define INSTANCE_H_

//#include "config.h"
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.

Nit: Remove if unnecessary.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

+1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the pattern in all other files, just to allow using autotools later. I'd like to keep it consistent.

Copy link
Copy Markdown

@qingling128 qingling128 left a comment

Choose a reason for hiding this comment

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

LGTM.

Comment thread src/configuration.cc
constexpr const int kMetadataIngestionDefaultRequestSizeLimitBytes =
8*1024*1024;
constexpr const char kMetadataIngestionDefaultRawContentVersion[] = "0.1";
constexpr const int kInstanceUpdaterDefaultIntervalSeconds = 60*60;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Makes sense. Thanks for the clarification.

Comment thread src/environment.cc
} else {
// Default to a GCE instance.
// TODO: Detect other resources.
instance_resource_type_ = kGceInstanceResourceType;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ah, right. Thanks for adding the comment!

Comment thread src/instance.cc Outdated
@@ -0,0 +1,63 @@
/*
* Copyright 2017 Google Inc.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤣

Comment thread src/instance.h
#ifndef INSTANCE_H_
#define INSTANCE_H_

//#include "config.h"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

+1

Comment thread src/environment.cc
} else {
// Default to a GCE instance.
// TODO: Detect other instance resources.
instance_resource_type_ = kGceInstanceResourceType;
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.

Is there a reason that config_.InstanceResourceType cannot default to "gce_instance"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current default (empty value) means "detect via the environment". I've added a comment in configuration.cc to that effect.

Copy link
Copy Markdown
Contributor Author

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL.

Comment thread src/configuration.cc Outdated
8*1024*1024;
constexpr const char kMetadataIngestionDefaultRawContentVersion[] = "0.1";
constexpr const int kInstanceUpdaterDefaultIntervalSeconds = 60*60;
constexpr const char kDefaultInstanceResourceType[] = "";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just added a comment to that effect.

Comment thread src/environment.cc
} else {
// Default to a GCE instance.
// TODO: Detect other instance resources.
instance_resource_type_ = kGceInstanceResourceType;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current default (empty value) means "detect via the environment". I've added a comment in configuration.cc to that effect.

Comment thread src/instance.h
#ifndef INSTANCE_H_
#define INSTANCE_H_

//#include "config.h"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the pattern in all other files, just to allow using autotools later. I'd like to keep it consistent.

Copy link
Copy Markdown
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

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

LGTM

@igorpeshansky igorpeshansky force-pushed the igorp-instance-resource branch from 5a9e66c to c1fa702 Compare February 23, 2018 20:57
@igorpeshansky
Copy link
Copy Markdown
Contributor Author

Rebased off master.

@igorpeshansky igorpeshansky merged commit 419d9ca into master Feb 23, 2018
@igorpeshansky igorpeshansky deleted the igorp-instance-resource branch February 23, 2018 21:13
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.

4 participants