-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Auth problems App Engine J8/Std --> Stackdriver Montoring API #2504
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
Comments
Hi @DazWilkin on App Engine J8 std, the underlying credential is actually ComputeEngine Credential, which is obtained through http call to metadata (code). I suspect something is wrong with obtaining ComputeEngine credential. Can you provide a sample app, so we can investigate ? |
@neozwu -- I included a Gist reference hoping that would help. If not, please let me know what you need and I'll provide. Heading out on vacation tomorrow so will do this today if I can. |
Treating as question for now. We should convert to bug if we determine that something here is not working as intended. |
@DazWilkin @brugz I am unable to reproduce this. Code and Since this issue is quite old, I suspect that the fix might have landed between then and now. So, I'll close the issue for the time being. Please reopen if you're still seeing the problem and we can help investigate more.
public void doGet(HttpServletRequest req, HttpServletResponse response) throws IOException {
try {
try (MetricServiceClient client = MetricServiceClient.create()) {
// Prepares an individual data point
TimeInterval interval =
TimeInterval.newBuilder()
.setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
.build();
TypedValue value = TypedValue.newBuilder().setDoubleValue(123.45).build();
Point point = Point.newBuilder().setInterval(interval).setValue(value).build();
List<Point> pointList = new ArrayList<>();
pointList.add(point);
ProjectName name = ProjectName.create(PROJECT_ID);
// Prepares the metric descriptor
Map<String, String> metricLabels = new HashMap<String, String>();
metricLabels.put("store_id", "Pittsburg");
Metric metric =
Metric.newBuilder()
.setType("custom.googleapis.com/stores/daily_sales")
.putAllLabels(metricLabels)
.build();
// Prepares the monitored resource descriptor
Map<String, String> resourceLabels = new HashMap<String, String>();
resourceLabels.put("project_id", PROJECT_ID);
MonitoredResource resource =
MonitoredResource.newBuilder().setType("global").putAllLabels(resourceLabels).build();
// Prepares the time series request
TimeSeries timeSeries =
TimeSeries.newBuilder()
.setMetric(metric)
.setResource(resource)
.addAllPoints(pointList)
.build();
List<TimeSeries> timeSeriesList = new ArrayList<>();
timeSeriesList.add(timeSeries);
CreateTimeSeriesRequest request =
CreateTimeSeriesRequest.newBuilder()
.setNameWithProjectName(name)
.addAllTimeSeries(timeSeriesList)
.build();
// Writes time series data
client.createTimeSeries(request);
response.setContentType("text/plain");
response.getWriter().println("Done writing time series data");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} |
Problem
Cloud Client Libraries (including Cloud Monitoring API v3) support Application Default Credentials and should use the App Engine service account to authenticate against other services. This does not appear to work as intended|documented:
com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED
A colleague provided a hack that obtains an access token using the App Engine service account and injects this into the credentials provided to the Cloud Monitoring API. This works but is unwieldy (see below) and should be unnecessary.
Repro
-- Maven generate an App Engine Standard J8 app
-- Mash-up w/ Google provided Custom Metric sample
-- Observe UNAUTHENTICATED problems auth'ing with
MetricServiceClient.create()
Solution
Caveat: I do not understand why this code works... it does
-- Revise
MetricServiceClient.create()
with:Here:
https://gist.github.com/DazWilkin/05b1a2ed702e78019e20e862df274129#file-testservlet-java-L52-L74
Thanks @salrashid123 for providing the solution.
The text was updated successfully, but these errors were encountered: