Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the app for GAE Go 1.12+ runtime #37

Merged
merged 13 commits into from
Sep 11, 2020
Merged

Conversation

Temikus
Copy link
Contributor

@Temikus Temikus commented Aug 30, 2020

Since bbolt which we plan to use as a storage engine requires Go 1.13+, we need to update the app to support GAE 1.12+ runtime (which we would've inevitably needed to do anyway).

Rough outline of changes here:

  • Moving to go modules
  • Changing the runtime to 1.13
  • Migrate logging to logrus
  • Remove urlfetch, appengine.Main() and other GAE library-specific routines
  • Get runtime info from ENV instead of using appengine lib
  • Change some config paths and associated docs due to different PWD

NOTE TO REVIEWER:
I know this is a large PR, but the migration scope is pretty large so I want to avoid merging commits that will make the project unbuildable. As such, I've partitioned the PR into small commits that should be limited in scope and easier to review. I plan to squash them after the review is finished.

- This is needed if we're dealing with storage engines that need additional operations to be performed (e.g. DB to be closed)
- Additionally, rename newConfig to newRuntimeConfig to make it less likely to confuse it with tsbridge.NewConfig
Currently this is just a no-op but is needed to support storage engines that need to close their DB's
@Temikus Temikus force-pushed the go_112_plus branch 8 times, most recently from bd049f2 to c99d093 Compare September 1, 2020 07:02
app/main.go Show resolved Hide resolved
datastore/datastore_manager.go Outdated Show resolved Hide resolved
datastore/emulator.go Outdated Show resolved Hide resolved
.travis.yml Show resolved Hide resolved
knyar
knyar previously requested changes Sep 3, 2020
app/main.go Outdated Show resolved Hide resolved
app/main.go Outdated Show resolved Hide resolved
datadog/metric_test.go Outdated Show resolved Hide resolved
datastore/emulator.go Outdated Show resolved Hide resolved
1.12+ runtime requires the app to use go modules
- Remove dep manifest, lock and vendor folder
- Add a .go-version file to use with goenv
AppEngine logging lib is no longer supported in 1.12+ runtimes
1.12+ doesn't support urlfetch
@Temikus Temikus force-pushed the go_112_plus branch 2 times, most recently from d959c3a to 9b3b38b Compare September 7, 2020 00:45
app/main.go Outdated Show resolved Hide resolved
datadog/metric_test.go Outdated Show resolved Hide resolved
datadog/metric_test.go Outdated Show resolved Hide resolved
code := m.Run()
done()
testCtxCancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

The shutdown code in the emulator probably won't be run here, there's a race condition with os.Exit(), the next line.

I'll have a chat with you about how to fix this outside this review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dparrish So as discussed I've decided to address this via returning a channel that gets pushed a message into it when it's done - PTAL

datadog/metric_test.go Outdated Show resolved Hide resolved
datadog/metric_test.go Outdated Show resolved Hide resolved
datastore/datastore_manager.go Outdated Show resolved Hide resolved
datastore/datastore_manager.go Show resolved Hide resolved
datastore/datastore_manager_test.go Outdated Show resolved Hide resolved
func Emulator(ctx context.Context) error {

// Set log formatter to process newlines since emulator gives a lot of output
log.SetFormatter(&log.TextFormatter{DisableQuote: true})
Copy link
Contributor

Choose a reason for hiding this comment

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

This changes the global logging state, probably not what you want. logrus can create child loggers with different formats which might be good here.

or move this SetFormatter line to main().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I dug quite a bit through the docs, but couldn't find specifics on child loggers, can you point at an example somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it via log.WithContext() PTAL

@Temikus Temikus force-pushed the go_112_plus branch 2 times, most recently from a599b0f to b97e6c3 Compare September 7, 2020 08:04
Since we can no longer use AppEngine SDK for it
Working dir is now module root so we need to change some things accordingly
In favour of generic serving, as suggested by the migration guide
- Match the go version with the .go-version
- Drop godep
- Update CloudSDK
@Temikus Temikus force-pushed the go_112_plus branch 2 times, most recently from 38523ea to 50bec22 Compare September 9, 2020 06:31
datadog/metric.go Outdated Show resolved Hide resolved
datadog/metric.go Outdated Show resolved Hide resolved
datadog/metric_test.go Outdated Show resolved Hide resolved
datadog/metric_test.go Outdated Show resolved Hide resolved
datadog/metric_test.go Outdated Show resolved Hide resolved
stackdriver/adapter_test.go Outdated Show resolved Hide resolved
tsbridge/config.go Show resolved Hide resolved
tsbridge/config_test.go Outdated Show resolved Hide resolved
setProjectID(fakeProjectID)
_, errNoProject := NewConfig(ctx, &ConfigOptions{Filename: "testdata/valid.yaml", Storage: storage})

if errNoProject == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

errNoProject really should just be err for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question - otherwise I'll get the No new variables on left side of := - is it ok to use = to redefine err?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you use the single-line form then you can redefine err! e.g. this is valid:

var err error
if err := Operation(); err != nil {
...
}

tsbridge/metric_test.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@Temikus Temikus left a comment

Choose a reason for hiding this comment

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

Fixed most of it - just 2 comments outstanding - PTAL.

if err == nil {
t.Error("expected an error when server returns 404")
}

// A query needs to return a single time series.
handler.filename = "multiple_ts.json"
_, _, err = m.StackdriverData(testCtx, time.Now().Add(-time.Minute), &datastore.StoredMetricRecord{})
_, _, err = m.StackdriverData(ctx, time.Now().Add(-time.Minute), &datastore.StoredMetricRecord{Storage: storage})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So genuine question here - if I do that - the function legit doesn't fit in my 27inch monitor - is it ok to leave it like this for readability sake?

datadog/metric.go Outdated Show resolved Hide resolved
datastore/datastore_record.go Outdated Show resolved Hide resolved
datastore/datastore_record_test.go Show resolved Hide resolved
datastore/emulator.go Outdated Show resolved Hide resolved
datastore/emulator.go Outdated Show resolved Hide resolved
datastore/emulator.go Outdated Show resolved Hide resolved
influxdb/metric_test.go Outdated Show resolved Hide resolved
stackdriver/adapter_test.go Outdated Show resolved Hide resolved
datastore/emulator.go Outdated Show resolved Hide resolved
datastore/emulator.go Outdated Show resolved Hide resolved
@Temikus Temikus dismissed knyar’s stale review September 11, 2020 02:28

Addressed all changes.

- Migrating to use cloud datastore libraries
- Add a client field to Datastore.manager and hold the client session info in it
- Add a datastore emulator harness (using `gcloud`) for tests as `gaetest` is no longer supported past Go 1.11
- Update tests & mocks

fixup
@Temikus Temikus changed the title [WORK IN PROGRESS] Update the app for GAE Go 1.12+ runtime Update the app for GAE Go 1.12+ runtime Sep 11, 2020
@Temikus Temikus merged commit 15c8d4d into google:master Sep 11, 2020
@Temikus Temikus deleted the go_112_plus branch September 11, 2020 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants