GoogleCloudPlatform / appengine-sidecars-docker

A set of services that run along side of your Google App Engine Flexible VM application containers. Each service runs inside of its own docker container along with your application's source code.
https://cloud.google.com/appengine/docs/flexible/
Apache License 2.0
72 stars 44 forks source link

internal.flushLog: Flush RPC: service bridge returned HTTP 400 ("App Engine APIs over the Service Bridge are disabled.\nIf they are required, enable them by setting the following to your app.yaml:\n\nbeta_settings:\n enable_app_engine_apis: true\n") #82

Closed githubwua closed 4 years ago

githubwua commented 6 years ago

The following error for GAE Go Flexible is logged every second:

internal.flushLog: Flush RPC: service bridge returned HTTP 400 ("App Engine APIs over the Service Bridge are disabled.\nIf they are required, enable them by setting the following to your app.yaml:\n\nbeta_settings:\n enable_app_engine_apis: true\n")

The error is coming from:

https://github.com/GoogleCloudPlatform/appengine-sidecars-docker/blob/master/api_proxy/proxy.go#L15

Please note that app.yaml is no longer using any custom runtime:

runtime: go api_version: go1.8 env: flexible

So, it should stop generating the logs above. Can we please stop logging the above message?

cnbuff410 commented 6 years ago

I'm getting this error all the time as well

mblasi commented 6 years ago

Hi! Any update on this?

I migrated from standard GAE to flexible environment, and faced this issue when trying to do a POST request to a resource outside my app.

Regards, Matías.

Cynocracy commented 6 years ago

Hi (and apologies for the late response :)),

This error should only occur when you're attempting to make requests over the compatibility service bridge (this would occur only if you're making HTTP requests to appengine.googleapis.internal). If that's the case, it's likely a library you use (or the runtime itself) is making these requests.

Do you have a repro? It'd be useful to help pin down what could be making these requests on our end.

mblasi commented 6 years ago

Thank you Cynocracy!

Here is the code I'm trying to run:

` func Mp(c *gin.Context) { ctx := trace.StartSpan(c, "mp.callback") defer trace.EndSpan(ctx)

defer logger.Flush()

b := bytes.NewBuffer(make([]byte, 0))
reader := io.TeeReader(c.Request.Body, b)

var mpAuth MPAuth
if err := json.NewDecoder(reader).Decode(&mpAuth); err != nil {
    respondWithError(http.StatusInternalServerError, "Couldn't decode token", err, c)
}

c.Request.Body = ioutil.NopCloser(b)

data := url.Values{}
data.Set("client_secret", "TEST-123456789")
data.Add("grant_type", "authorization_code")
data.Add("code", mpAuth.Code)
data.Add("redirect_uri", mpAuth.RedirectUri)

method, err := http.NewRequest(http.MethodPost, "https://api.mercadopago.com/oauth/token", bytes.NewBufferString(data.Encode()))

if err != nil {
    respondWithError(http.StatusInternalServerError, "Error creating MP Post method: ", err, c)
}

method.Header.Add("accept", "application/json")
//method.Header.Add("content-type", "application/x-www-form-urlencoded")
method.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value")
method.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))

client := urlfetch.Client(appengine.BackgroundContext())

resp, err := client.Do(method)

if err != nil {
    respondWithError(http.StatusInternalServerError, "Error retrieving MP token", err, c)
} else if resp == nil {
    respondWithError(http.StatusInternalServerError, "Response vacío", errors.New(""), c)
} else {

    defer resp.Body.Close()
    response, _ := ioutil.ReadAll(resp.Body)

    var dat map[string]interface{}
    if err := json.Unmarshal(response, &dat); err != nil {
        respondWithError(http.StatusInternalServerError, "Error unmarshaling data: ", err, c)
    }

    c.JSON(http.StatusOK, dat)
}

} `

I get the error from the client.Do(method) line.

I dont know if it is the case you pointed out. The real thing is I need to make a post to an external resource... it is an external system implementing oauth2.

Please, let me know if it is enough for you.

Best regards, Matías.

mblasi commented 6 years ago

I also created this issue in the public tracker: https://issuetracker.google.com/u/2/issues/71050584

Cynocracy commented 6 years ago

Ah, I see the issue:

URLFetch is itself a compatibility API, you should be able to make HTTP requests normally using something idiomatic in the language. For go, I suppose that means the http package https://golang.org/pkg/net/http/

The main differences between Flex and Standard is the lack of these APIs, as well as an easier access to 'external' resources, so it makes sense that there'd be some confusion here. If there are any docs you think should be updated, feel free to link them and I can try to get someone to take a look :)

mblasi commented 6 years ago

Thank you very much Cynocracy! I'll be working on that then... Regarding the documentation, in my humble opinion it is little confusing about standard and flexible differences, for example, this page: https://cloud.google.com/appengine/docs/flexible/go/migrating says:

URL Fetch

The flexible environment has no sandbox restrictions, so you can use any HTTP library.

In the other hand, this page: https://cloud.google.com/appengine/docs/flexible/go/flexible-for-standard-users says:

Accessing external services

In the standard environment, your application typically accesses services such as Cloud Datastore via the built-in google.appengine APIs. However, in the flexible environment, these APIs are no longer available. Instead, use the Google Cloud client libraries. These client libraries work everywhere, which means that your application is more portable. If needed, applications that run in the flexible environment can usually run on Kubernetes Engine or Compute Engine without heavy modification.

Anyhow, now, it is more clear for me!

I appreciate your support and, I'd like to take advantage of this thread to ask you about one more confusions between standard and flexible flavors: it is about the tracing mechanism.

I started a couple of threads in gce-discussion forum:

Main thread: https://groups.google.com/forum/#!topic/gce-discussion/1INCUtvc300 Two smaller questions:

The main thread, despite of it is working for me now, it focuses on the confusing documentation, pleaste take a look on my posts. I'm still waiting for a clearer documentation about stackdriver an app engine...

Thanks again! Matías.

patthehuman commented 5 years ago

What is the status of this? These errors just started flooding my logs. Is this whats causing my server to lag horribly?

Sanrag commented 4 years ago

The api_proxy sidecar has now been deleted.