question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why is the python code so much smaller than the Java/C#? We should have similar (small) verbosity on all the platforms. I see no good reason not to create a nice DSL on top of the more verbose builders.

Example: python code to read timeseries:

client = monitoring.Client()
metric = 'compute.googleapis.com/instance/cpu/utilization'
query_results = client.query(metric, minutes=5).iter(headers_only=True)
for result in query_results:
    print(result)

vs java code to read timeseries

MetricServiceClient metricServiceClient = MetricServiceClient.create();
String projectId = System.getProperty("projectId");
ProjectName name = ProjectName.create(projectId);

// Restrict time to last 20 minutes
long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
TimeInterval interval = TimeInterval.newBuilder()
    .setStartTime(Timestamps.fromMillis(startMillis))
    .setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
    .build();

ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder()
    .setNameWithProjectName(name)
    .setFilter("metric.type=\"compute.googleapis.com/instance/cpu/utilization\"")
    .setInterval(interval)
    .setView(ListTimeSeriesRequest.TimeSeriesView.HEADERS);

ListTimeSeriesRequest request = requestBuilder.build();

PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient
    .listTimeSeries(request);

System.out.println("Got timeseries headers: ");
for (TimeSeries ts : response.iterateAll()) {
  System.out.println(ts);
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jabubakecommented, Aug 11, 2017

That being said : I still think its worth thinking of how we could simplify some of the generic statements here, which might be applicable across multiple libraries.

Constructing a resource ProjectName with the projectId : comes up for Pub/Sub as well. It would be good to users to provide projectId if required, and allow for the generated code to autodetect projectId with ServiceOptions.getDefaultProjectId().

String projectId = System.getProperty("projectId");
ProjectName name = ProjectName.create(projectId);

A TimeInterval helper which can possibly provide a start/end time and duration, so this amount of code does n’t become necessary. Java users are used to simpler ways of building time intervals like here.

// Restrict time to last 20 minutes
long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
TimeInterval interval = TimeInterval.newBuilder()
    .setStartTime(Timestamps.fromMillis(startMillis))
    .setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
    .build();
0reactions
anthmgooglecommented, Nov 9, 2017

It looks like this has answered the original question, acknowledging that it is still not as concise the as the Python. Please reopen or create a new issue if there is further iteration required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

#28 - Avoid chattiness in REST APIs
Chatty API is one that requires consumer to make tremendous (subjective matter) amount of distinct API calls to get needed information about ...
Read more >
Chatty I/O antipattern - Performance antipatterns for cloud apps
For example, the following web API exposes the individual properties of User objects through individual HTTP GET methods.
Read more >
How to balance chunkiness against chattiness when ...
Consumers can balance between chunky responses and chatty API calls all by themselves. One thing worth mentioning is the performance of the Hash ......
Read more >
API Reference – chatty v0.5.0 - HexDocs
Chatty. This module defines the public API for interacting with the IRC connection and the hook mechanism. Chatty.Connection · Chatty.Connection.UserInfo.
Read more >
A look at chatty vs chunky RESTful web services | On the ROA
Chatty services tend to be ones that return simplified information and use more fine-grained operations. Chunky services tend to return ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found