Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions applicationinsights/data-plane/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got mvn test working properly for me.

<version>1.0.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>
${project.build.outputDirectory}/maven.properties
</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public void canQuery() {
public void canGetMetric() {
MetricsResult metricResult = applicationInsightsClient.metrics().get(appId, MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE);
// Validate properties
Assert.assertNotNull(metricResult.value().additionalProperties());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the client doesn't properly populate this field from JSON? Here's what the return shape from API looks like, but the assert fails. I would expect something like metricResult.value().additionalProperties().get("availabilityResults/availabilityPercentage") should work, but metricResult.value().additionalProperties() is null.

{
  "value": {
    "start": "2018-09-10T07:47:08.518Z", 
    "end":"2018-09-10T19:47:08.518Z",
    "availabilityResults/availabilityPercentage": {
      "avg":100
    }
  }
}

System.out.println(metricResult.value().additionalProperties().keySet());
Assert.assertNotNull(metricResult.value().start());
Assert.assertTrue(metricResult.value().start() instanceof DateTime);
}
Expand Down Expand Up @@ -89,8 +91,6 @@ public void canGetMetricsMetadata() {
@Test
public void canGetEventsByType() {
EventsResults eventsResult = applicationInsightsClient.events().getByType(appId, EventType.AVAILABILITY_RESULTS);
System.out.println(eventsResult.value().get(0));
System.out.println(eventsResult.value().get(0).id());
Assert.assertNotNull(eventsResult.value().get(0).id());
}

Expand All @@ -100,11 +100,4 @@ public void canGetEvent() {
EventsResults eventsResult = applicationInsightsClient.events().get(appId, EventType.AVAILABILITY_RESULTS, eventId);
Assert.assertNotNull(eventsResult.value().get(0).id());
}

@Test
public void canGetEventsOdataMetadata() {
Object metadata = applicationInsightsClient.events().getOdataMetadata(appId);
// Sanity check
Assert.assertNotNull(metadata);
}
}
51 changes: 51 additions & 0 deletions loganalytics/data-plane/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Azure Log Analytics

This project provides client tools or utilities in Java that make it easy to query data in [Azure Log Analytics](https://azure.microsoft.com/en-us/services/log-analytics/). For reference documentation on classes and models, please see the [Azure SDK for Java reference](https://docs.microsoft.com/en-us/java/api/overview/azure/?view=azure-java-stable).

Azure Log Analytics provides agents for telemtry collection and enables deep analytics via a [rich query language](https://docs.loganalytics.io/index). This SDK provides query access to data already stored in Log Analytics. To start collecting data from different sources, take a look at these [quickstarts](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-quick-collect-azurevm).

## Examples

Please see [here](src/main/java/com/microsoft/azure/loganalytics/samples) for code examples using this SDK.


## Download

### Latest release

To get the binaries of the official Microsoft Azure Log Analytics SDK as distributed by Microsoft, reade for use within your project, you can use Maven.

```xml
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-loganalytics</artifactId>
<version>LATEST</version>
</dependency>
```

## Prerequisites

- A Java Developer Kit (JDK), v 1.7 or later
- Maven

## Help and Issues

If you encounter any bugs with these SDKs, please file issues via [Issues](https://github.com/Azure/azure-sdk-for-java/issues) or checkout [StackOverflow for Azure Java SDK](http://stackoverflow.com/questions/tagged/azure-java-sdk).

## Contribute Code

If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html).

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

## More information
- [Azure Java SDKs](https://docs.microsoft.com/java/azure/)
- If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212)

---

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
21 changes: 21 additions & 0 deletions loganalytics/data-plane/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>
${project.build.outputDirectory}/maven.properties
</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -141,6 +159,9 @@
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
</includes>
<excludes>
<exclude>**/LogAnalyticsDataClientTests.java</exclude>
</excludes>
<environmentVariables>
<test.mode>${testMode}</test.mode>
</environmentVariables>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.util.List;
import java.util.stream.Collectors;
import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.loganalytics.implementation.LogAnalyticsDataClientImpl;
import com.microsoft.azure.loganalytics.models.QueryBody;
import com.microsoft.azure.loganalytics.models.QueryResults;
import com.microsoft.azure.credentials.ApplicationTokenCredentials;

/**
* Basic query example
*
*/
public class BasicSample
{
public static void main( String[] args )
{
// ApplicationTokenCredentials work well for service principal authentication
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
"<clientId>",
"<tenantId>",
"<clientSecret>",
AzureEnvironment.AZURE
);

// New up client. Accepts credentials, or a pre-authenticated restClient
LogAnalyticsDataClientImpl client = new LogAnalyticsDataClientImpl(credentials);

// Prepare information for query
String query = "Heartbeat | take 1";
String workspaceId = "<logAnalyticsWorkspaceGUID>";

// Execute!
QueryResults queryResults = client.query(workspaceId, new QueryBody().withQuery(query));

// Process and print results
List<Object> row = queryResults.tables().get(0).rows().get(0);
List<String> columnNames = queryResults
.tables()
.get(0)
.columns()
.stream()
.map(elt -> elt.name())
.collect(Collectors.toList());

for (int i = 0; i < row.size(); i++){
System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i));
}

return;
}
}
```