// Path: java-runtimes-common/test-spring-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java
// @Service
// public class StackDriverMonitoringService {
// 
//     @Autowired
//     private ApplicationContext applicationContext;
// 
//     @Value("${monitoring.write.retries}")
//     private int maxRetries;
//     private static Logger LOG = Logger.getLogger(StackDriverMonitoringService.class.getName());
// 
// 
//     public void createMetricAndInsertTestToken(String projectId, String metricType, long metricValue) throws IOException {
//         int retries = maxRetries;
//         while (retries > 0) {
//             try {
//                 CreateTimeSeriesRequest timeSeriesRequest = createTimeSeriesRequest(projectId, metricType, metricValue);
//                 getClient().createTimeSeries(timeSeriesRequest);
//                 LOG.info("Metric created with timeseries.");
//                 return;
//             } catch (Exception e) {
//                 LOG.warning("error creating timeseries request, retrying..." + e.getClass() + ": " + e.getMessage());
//                 retries--;
//                 if (retries == 0) {
//                     throw new IllegalStateException("Failed to store timeseries after " + maxRetries + " attempts! Last error:", e);
//                 }
//             }
//         }
//     }
// 
//     /**
//      * This pairs up with the @Lazy annotation on {@link GcpConfiguration#getMetricServiceClient()}.
//      * As MetricServiceClient methods are all `final` and that breaks the "@Autowire @Lazy" combination,
//      * this is the only way to wire this bean lazily.
//      */
//     private MetricServiceClient getClient() {
//         return (MetricServiceClient) applicationContext.getBean("metricServiceClient");
//     }
// 
//     private CreateTimeSeriesRequest createTimeSeriesRequest(String projectId, String metricType, Long metricValue) {
//         LOG.info("Creating time series to insert token: " + metricValue);
//         ProjectName projectName = ProjectName.create(projectId);
//         Metric metric = Metric.newBuilder()
//                 .setType(metricType)
//                 .build();
//         TimeInterval interval = TimeInterval.newBuilder()
//                 .setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
//                 .build();
//         TypedValue pointValue = TypedValue.newBuilder()
//                 .setInt64Value(metricValue)
//                 .build();
//         Point point = Point.newBuilder()
//                 .setInterval(interval)
//                 .setValue(pointValue)
//                 .build();
//         TimeSeries timeSeries = TimeSeries.newBuilder()
//                 .setMetric(metric)
//                 .setMetricKind(MetricDescriptor.MetricKind.GAUGE)
//                 .setResource(MonitoredResource.newBuilder().setType("global").build())
//                 .addPoints(point)
//                 .build();
//         return CreateTimeSeriesRequest.newBuilder()
//                 .setNameWithProjectName(projectName)
//                 .addTimeSeries(timeSeries)
//                 .build();
//     }
// 
// 
// }


import com.google.cloud.runtimes.stackdriver.StackDriverMonitoringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.logging.Logger;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
package com.google.cloud.runtimes;




@RestController
public class MonitoringTestController {

    @Autowired
    @Lazy
    private StackDriverMonitoringService stackDriverMonitoringService;

    @Autowired
    @Qualifier("projectId")
    private String projectId;

    private static Logger LOG = Logger.getLogger(MonitoringTestController.class.getName());

    public static class MonitoringTestRequest {
        private String name;
        private Long token;

        public void setToken(Long token) {
            this.token = token;
        }

        public void setName(String name) {
// Path: java-runtimes-common/test-spring-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java
// @Service
// public class StackDriverMonitoringService {
// 
//     @Autowired
//     private ApplicationContext applicationContext;
// 
//     @Value("${monitoring.write.retries}")
//     private int maxRetries;
//     private static Logger LOG = Logger.getLogger(StackDriverMonitoringService.class.getName());
// 
// 
//     public void createMetricAndInsertTestToken(String projectId, String metricType, long metricValue) throws IOException {
//         int retries = maxRetries;
//         while (retries > 0) {
//             try {
//                 CreateTimeSeriesRequest timeSeriesRequest = createTimeSeriesRequest(projectId, metricType, metricValue);
//                 getClient().createTimeSeries(timeSeriesRequest);
//                 LOG.info("Metric created with timeseries.");
//                 return;
//             } catch (Exception e) {
//                 LOG.warning("error creating timeseries request, retrying..." + e.getClass() + ": " + e.getMessage());
//                 retries--;
//                 if (retries == 0) {
//                     throw new IllegalStateException("Failed to store timeseries after " + maxRetries + " attempts! Last error:", e);
//                 }
//             }
//         }
//     }
// 
//     /**
//      * This pairs up with the @Lazy annotation on {@link GcpConfiguration#getMetricServiceClient()}.
//      * As MetricServiceClient methods are all `final` and that breaks the "@Autowire @Lazy" combination,
//      * this is the only way to wire this bean lazily.
//      */
//     private MetricServiceClient getClient() {
//         return (MetricServiceClient) applicationContext.getBean("metricServiceClient");
//     }
// 
//     private CreateTimeSeriesRequest createTimeSeriesRequest(String projectId, String metricType, Long metricValue) {
//         LOG.info("Creating time series to insert token: " + metricValue);
//         ProjectName projectName = ProjectName.create(projectId);
//         Metric metric = Metric.newBuilder()
//                 .setType(metricType)
//                 .build();
//         TimeInterval interval = TimeInterval.newBuilder()
//                 .setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
//                 .build();
//         TypedValue pointValue = TypedValue.newBuilder()
//                 .setInt64Value(metricValue)
//                 .build();
//         Point point = Point.newBuilder()
//                 .setInterval(interval)
//                 .setValue(pointValue)
//                 .build();
//         TimeSeries timeSeries = TimeSeries.newBuilder()
//                 .setMetric(metric)
//                 .setMetricKind(MetricDescriptor.MetricKind.GAUGE)
//                 .setResource(MonitoredResource.newBuilder().setType("global").build())
//                 .addPoints(point)
//                 .build();
//         return CreateTimeSeriesRequest.newBuilder()
//                 .setNameWithProjectName(projectName)
//                 .addTimeSeries(timeSeries)
//                 .build();
//     }
// 
// 
// }


// Path: java-runtimes-common/test-spring-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java
import com.google.cloud.runtimes.stackdriver.StackDriverMonitoringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.logging.Logger;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

package com.google.cloud.runtimes;




@RestController
public class MonitoringTestController {

    @Autowired
    @Lazy
    private StackDriverMonitoringService stackDriverMonitoringService;

    @Autowired
    @Qualifier("projectId")
    private String projectId;

    private static Logger LOG = Logger.getLogger(MonitoringTestController.class.getName());

    public static class MonitoringTestRequest {
        private String name;
        private Long token;

        public void setToken(Long token) {
            this.token = token;
        }

        public void setName(String name) {
            this.name = name;