org.springframework.cloud.sleuth.annotation.NewSpan Java Examples

The following examples show how to use org.springframework.cloud.sleuth.annotation.NewSpan. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CacheServer.java    From coolretailer with Apache License 2.0 6 votes vote down vote up
@NewSpan
@Override
public void getSuggestions(Query query, StreamObserver<Result> responseObserver) {
    LOGGER.info("Got prefix: " + query.getQueryString());
    try {

        List<String> suggestions = cacheProcessor.getSuggestions(query.getQueryString());
        if (CollectionUtils.isEmpty(suggestions)) {
            suggestions = new ArrayList<String>();
        }
        Result.Builder responseBuilder = Result.newBuilder()
                .addAllName(suggestions);
        responseObserver.onNext(responseBuilder.build());
        responseObserver.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Exception: " + e);
    }
}
 
Example #2
Source File: QueryService.java    From coolretailer with Apache License 2.0 6 votes vote down vote up
@NewSpan
@RequestMapping("/api/fetchProducts")
public String fetchProducts(@RequestParam("name") String prefix, HttpServletRequest request,
		HttpServletResponse response) throws Exception {
	if (prefix.length() < 2) {
		return "";
	}
	processHeaders(request, response);

	String filter = "[^A-Za-z0-9 ()-]";
	LOGGER.info("Fetch suggestions for: " + prefix);
	List<String> suggestions = queryProcessor.getSuggestions(prefix.replaceAll(filter, "").toLowerCase());
	if (!CollectionUtils.isEmpty(suggestions)) {
		LOGGER.info("Found " + suggestions.toString());
		return (new Gson().toJson(suggestions));
	}
	return "[]";

}
 
Example #3
Source File: CacheProcessor.java    From coolretailer with Apache License 2.0 6 votes vote down vote up
@NewSpan
public void run(ApplicationArguments args) throws Exception {
	if (args.containsOption("clear-cache")) {
		clearCache();
	}

	if (args.containsOption("process-cache")) {
		List<String> cacheOptions = args.getOptionValues("process-cache");
		if (cacheOptions.size() == 1) {
			processCache(cacheOptions.get(0));
		} else {
			processCache(null);
		}
		if (args.containsOption("exit")) {
			Runtime.getRuntime().halt(0);
		}
	}
}
 
Example #4
Source File: DataServer.java    From coolretailer with Apache License 2.0 5 votes vote down vote up
@NewSpan
@Override
public void updateCache(Query query, StreamObserver<Result> responseObserver) {
    LOGGER.info("Got query: " + query);
    try {
        Result.Builder responseBuilder = Result.newBuilder()
                .addAllName(bqProcessor.processQuery(query.getQueryString(), String.class, true));
        responseObserver.onNext(responseBuilder.build());
        responseObserver.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Exception: " + e);
    }
}
 
Example #5
Source File: BeanConversionService.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@Override
@NewSpan("conversion")
public <U> U convert(Object source, @SpanTag("target") Class<U> targetClass) {
    if (source == null) {
        return null;
    }
    if (tracer != null) {
        tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, BeanConversionService.class.getName());
        tracer.addTag("source", "class " + source.getClass().getName());
    }
    if (source.getClass().equals(targetClass)) {
        return (U) source;
    }
    try {
        U converted = targetClass.newInstance();
        copyBean(source, converted);

        List<Registration<Object>> registrationsFound = getRegistrationsForSourceClass(source.getClass());

        List<BiFunction<Object, U, U>> customs = new ArrayList<>();
        for (Registration<Object> registrationFound : registrationsFound) {
            customs.addAll(getRegistrationFunctions(targetClass, registrationFound));
        }

        U result = converted;
        for (BiFunction<Object, U, U> current : customs) {
            result = current.apply(source, converted);
        }

        return result;
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: WorkService.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@NewSpan
public void visitMeetEndpoint(String meetUrl) {
	LOGGER.info("starting busy work");
	for (int i = 0; i < 3; i++) {
		this.restTemplate.getForObject(meetUrl, String.class);
	}
	LOGGER.info("finished busy work");
}
 
Example #7
Source File: MessageListener.java    From rqueue with Apache License 2.0 5 votes vote down vote up
@RqueueListener(
    value = "job-queue",
    deadLetterQueue = "job-morgue",
    numRetries = "2",
    concurrency = "1-3",
    active = "true")
@NewSpan
public void onMessage(Job job) {
  execute("job-queue: {}", job);
  if (shouldFail()) {
    throw new IllegalStateException("OMG!" + job);
  }
}
 
Example #8
Source File: MessageListener.java    From rqueue with Apache License 2.0 5 votes vote down vote up
@RqueueListener(
    value = {"${rqueue.delay.queue}", "${rqueue.delay2.queue}"},
    numRetries = "${rqueue.delay.queue.retries}",
    visibilityTimeout = "60*60*1000",
    active = "true")
@NewSpan
public void onMessage(String message) {
  execute("delay: {}", message);
  if (shouldFail()) {
    throw new NullPointerException("Failing On Purpose " + message);
  }
}
 
Example #9
Source File: QueryProcessor.java    From coolretailer with Apache License 2.0 5 votes vote down vote up
@NewSpan
public List<String> getSuggestions(String searchPrefix) throws Exception {
	LOGGER.info("Calling cacheservice with: " + searchPrefix);
	Query query = Query.newBuilder().setQueryString(searchPrefix).build();
	return cacheServiceBlockingStub.getSuggestions(query).getNameList();

}
 
Example #10
Source File: DataServer.java    From coolretailer with Apache License 2.0 5 votes vote down vote up
@NewSpan
@Override
public void runQuery(Query query, StreamObserver<Result> responseObserver) {
    LOGGER.info("Got query: " + query);
    try {
        Result.Builder responseBuilder = Result.newBuilder()
                .addAllName(bqProcessor.processQuery(query.getQueryString(), String.class, false));
        responseObserver.onNext(responseBuilder.build());
        responseObserver.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Exception: " + e);
    }
}
 
Example #11
Source File: CacheServer.java    From coolretailer with Apache License 2.0 5 votes vote down vote up
@NewSpan
@Override
public void clearCache(Empty empty, StreamObserver<Empty> responseObserver) {
    LOGGER.info("Clearing cache: ");
    try {
        cacheProcessor.clearCache();
        responseObserver.onNext(Empty.newBuilder().build());
        responseObserver.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Exception: " + e);
    }
}
 
Example #12
Source File: CacheServer.java    From coolretailer with Apache License 2.0 5 votes vote down vote up
@NewSpan
@Override
public void processCache(Limit limit, StreamObserver<Empty> responseObserver) {
    LOGGER.info("Loading " + limit.getLimit() + " items to cache...");
    try {
        cacheProcessor.processCache(String.valueOf(limit.getLimit()));
        responseObserver.onNext(Empty.newBuilder().build());
        responseObserver.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Exception: " + e);
    }
}
 
Example #13
Source File: CacheProcessor.java    From coolretailer with Apache License 2.0 5 votes vote down vote up
@NewSpan
public List<String> processQuery(String queryString, boolean updateCache) throws Exception {
	Query query = Query.newBuilder().setQueryString(queryString).build();
	List<String> names = new ArrayList<String>();
	if (updateCache) {
		dataserviceBlockingStub.updateCache(query);
		LOGGER.info("Cache updated!");
	} else {
		names = dataserviceBlockingStub.runQuery(query).getNameList();
	}

	return names;
}
 
Example #14
Source File: CacheProcessor.java    From coolretailer with Apache License 2.0 5 votes vote down vote up
@NewSpan
public void processCache(String limit) throws Exception {
	LOGGER.info("Calling BigQuery...");
	LOGGER.info("Updating cache...");
	StringBuffer qb = new StringBuffer("SELECT name FROM coolretailer.products");
	if (limit != null) {
		qb.append(" LIMIT " + limit);

	}
	processQuery(qb.toString(), true);

}
 
Example #15
Source File: BQProcessor.java    From coolretailer with Apache License 2.0 4 votes vote down vote up
@NewSpan()
public <T> List<T> processQuery(String queryString, Class<T> t, boolean updateCache) throws Exception {

	QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(queryString).build();
	// Create a job ID so that we can safely retry.
	JobId jobId = JobId.of(UUID.randomUUID().toString());
	Job queryJob = bqInstance.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());

	// Wait for the query to complete.
	queryJob = queryJob.waitFor();

	// Check for errors
	if (queryJob == null) {
		throw new RuntimeException("Job no longer exists");
	} else if (queryJob.getStatus().getError() != null) {
		// You can also look at queryJob.getStatus().getExecutionErrors() for all
		// errors, not just the latest one.
		throw new RuntimeException(queryJob.getStatus().getError().toString());
	}

	// Get the results.
	TableResult result = queryJob.getQueryResults();
	// init counters
	long count = 0;
	long total = result.getTotalRows();
	LOGGER.info("Fetched " + total + " products.");
	long start = System.currentTimeMillis();
	// Print all pages of the results.
	List<T> results = new ArrayList<T>();
	// filter
	String filter = "[^A-Za-z0-9 ()-]";
	while (result != null) {
		for (List<FieldValue> row : result.iterateAll()) {
			Object type = t.getConstructor().newInstance();
			String productName = null;
			// query for sku, name
			if (type instanceof Product) {
				productName = row.get(1).getValue() != null
						? row.get(1).getStringValue().replaceAll(filter, "").trim()
						: "";
				if (!updateCache) {
					Product product = new Product();
					product.setSku(row.get(0).getValue().toString());

					product.setName(productName);
					results.add(t.cast(product));
				}
				// query for name
			} else if (type instanceof String) {
				productName = row.get(0).getValue() != null
						? row.get(0).getStringValue().replaceAll(filter, "").trim()
						: "";
				if (!updateCache) {
					results.add(t.cast(productName));
				}
			}

			if (updateCache) {
				getZSetOps().add(productName.toLowerCase() + ":" + productName, 0);
			}
			count++;
		}
		LOGGER.info("Processed " + count + " records..");
		result = result.getNextPage();
	}
	if (updateCache) {
		long actual = getZSetOps().zCard();
		LOGGER.info("Indexing completed for " + count + " products.");
		LOGGER.info("Products in cache: " + actual);
		LOGGER.info("Duplicate product names: " + (count - actual));
		LOGGER.info("Time taken: " + (System.currentTimeMillis() - start) / 1000 + "s.");
	}

	return results;

}
 
Example #16
Source File: MessageListener.java    From rqueue with Apache License 2.0 4 votes vote down vote up
@RqueueListener(value = "${rqueue.simple.queue}", active = "true")
@NewSpan
public void consumeMessage(String message) {
  execute("simple: {}", message);
}
 
Example #17
Source File: CacheProcessor.java    From coolretailer with Apache License 2.0 4 votes vote down vote up
@NewSpan
public void clearCache() {
	template.delete("autocomplete");
	LOGGER.info("Cleared cache.");
}
 
Example #18
Source File: SleuthBenchmarkingSpringApp.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@NewSpan
public String newSpan() {
	return this.anotherClass.continuedAnnotation("bar");
}