Commit 9a15910b authored by George Tziavas's avatar George Tziavas
Browse files

single thread used per query

parent 009f5857
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@

	<artifactId>org.etsi.osl.metrico</artifactId>
	<name>org.etsi.osl.metrico</name>
<!--	<version>${org.etsi.osl.cridge.version}</version>-->
<!--	<version>${org.etsi.osl.metrico.version}</version>-->
	<url>http://openslice.io</url>

	<organization>
+7 −18
Original line number Diff line number Diff line
package org.etsi.osl.metrico.prometheus;


import org.etsi.osl.metrico.model.Job;
import org.etsi.osl.metrico.services.JobService;
import org.etsi.osl.tmf.pm628.model.ExecutionStateType;
@@ -8,7 +7,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

@@ -16,9 +14,6 @@ import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.concurrent.TimeUnit;

/**
 * This class contains the Prometheus Queries for the metrics.
 */
@Component
public class PrometheusQueries {

@@ -39,25 +34,18 @@ public class PrometheusQueries {

        ResponseEntity<String> response = restTemplate.getForEntity(builder.toUriString(), String.class);
        logger.atDebug().log("Received " + response.getBody());
        return response.getBody();  // This will be sent to the MQ
        return response.getBody();
    }

    public Job startPeriodicQuery(String prometheusUrl, String query, OffsetDateTime startDateTime, OffsetDateTime endDateTime, Integer executionInterval) {

        final Runnable queryHandler = new Runnable() {
            public void run() {
                new Thread(() -> {

                    sendQueryToPrometheus(prometheusUrl, query);
        final Runnable queryHandler = () -> sendQueryToPrometheus(prometheusUrl, query);

                }).start();
            }
        };
        Job job = jobService.startJob(queryHandler, startDateTime, endDateTime, executionInterval);
        if (job.getState() == ExecutionStateType.FAILED) {
            return job;
        }
        // Schedule a task to stop the job after the specified delay

        if (endDateTime != null) {
            long stopAfterSeconds = Duration.between(OffsetDateTime.now(), endDateTime).getSeconds();
            JobService.getScheduler().schedule(() -> {
@@ -65,8 +53,9 @@ public class PrometheusQueries {
                job.setState(ExecutionStateType.COMPLETED);
            }, stopAfterSeconds, TimeUnit.SECONDS);
        }

        return job;
    }
}

}
+4 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import org.etsi.osl.tmf.pm628.model.ExecutionStateType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.Duration;
@@ -22,8 +23,10 @@ public class JobService {
    @Getter
    private static final Map<UUID, Job> jobs = new ConcurrentHashMap<>();

    @Value("${METRICO_THREAD_POOL_SIZE}")
    private static int threadPoolSize;
    @Getter
    private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(threadPoolSize);

    private final JobRepoService jobRepoService;

+3 −0
Original line number Diff line number Diff line
@@ -61,6 +61,9 @@ logging:
    
scheduling.enabled: true

#NUMBER OF THREADS FOR THE METRICO THREAD POOL
METRICO_THREAD_POOL_SIZE: 10

#TMF QUEUES
PM_GET_MEASUREMENT_COLLECTION_JOB_BY_ID: "jms:queue:PM.GET.MEASUREMENTCOLLECTIONJOB_BY_ID"
PM_GET_MEASUREMENT_COLLECTION_JOBS: "jms:queue:PM.GET.MEASUREMENTCOLLECTIONJOBS"
+4 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ public class MetricoServiceTest {
        mcj = new MeasurementCollectionJob();
        mcj.setUuid("123e4567-e89b-12d3-a456-426614174000");

        mcj.granularity(Granularity.G_1M);
        mcj.granularity(Granularity.G_10SEC);

        DataAccessEndpoint dae = new DataAccessEndpoint();
        dae.setApiType("PROMETHEUS");
@@ -48,11 +48,13 @@ public class MetricoServiceTest {
    public void testQueryToPrometheus() {
        String[] result = metricoService.queryToPrometheus(mcj);
        System.out.println(Arrays.toString(result));

        //assertEquals("OK", result);
    }

    @Test
    public void testStartPeriodicQueryToPrometheus(){
    public void testStartPeriodicQueryToPrometheus() throws InterruptedException {
        metricoService.startPeriodicQueryToPrometheus(mcj);
        Thread.sleep(60000);
    }
}
 No newline at end of file
Loading