Defining a microservice

This document describes how to create custom services and services for GKE- and Cloud Run-based resources.

In Cloud Monitoring, a service is a construct that you can associate with SLOs and alerting policies. Several of the resources for which you might create Monitoring services are also referred to as services, but with different meanings, like GKE services or Cloud Run services.

Monitoring can recognize GKE- and Cloud Run-based services as candidates for monitoring. To create services for them, you indicate which candidates you want to be treated as Monitoring services; Monitoring creates the necessary infrastructure for you.

You can also define arbitrary custom services.

Identify or create a service

To identify candidate services, or to create custom services, go to the Define service pane:

  1. In the navigation panel of the Google Cloud console, select Monitoring, and then select  SLOs:

    Go to SLOs

  2. On the Services Overview page, do one of the following:

    • Click Define service.

    • In the Current status pane, click the Define service link:

      Create custom and user-identfied services by using **Define service**.

From the Define service pane, you can do the following:

  • Create GKE- or Cloud Run-based services from a list of candidate services.
  • Define custom services.

The following sections describe these options.

Create GKE- and Cloud Run-based services

Cloud Monitoring can identify potential services of the following types:

  • GKE namespaces
  • GKE services
  • GKE workloads
  • Cloud Run service

Because there might be many of these potential services, Monitoring doesn't assume you want them all to be treated as services with SLOs. To indicate which of the potential services Monitoring should treat as services, you use either the Google Cloud console or the API.

Use the Google Cloud console to create GKE and Cloud Run services

To identify a GKE- or Cloud Run-based Monitoring service by using the Google Cloud console, do the following:

  1. On the Services Overview page, click Define service.

  2. Select Service Candidates.

    Potential services are listed on the **Service Candates** tab.

    There might be a large number of candidate services in the list. You can filter the list as follows:

    1. Click Filter table. A list of filter options is displayed.

    2. Select one of the options on the filter list. The selected option appears in the filter bar.

    3. Click next to the option in the filter bar and start typing. Values that match are provided on a list. Select a value from the list.

  3. Click a candidate service from the list of potential services.

    When you click an entry, the following fields are filled in for you:

    • The display name is set to the name the entry in the list. You can change this value.

    • A block of JSON code for the configuration of the new service is generated from the candidate. Do not change this value.

  4. Click Submit. When your service is created, a Success notice is displayed.

Use the API to create GKE and Cloud Run services

GKE- and Cloud Run-based services can also be defined by using the SLO API, part of the Cloud Monitoring API.

To create a service programmatically, post a configuration object like one of the following to the services.create method:

GKE namespace

Use the GkeNamespace structure, for example:

{
  "displayName": "test-kube-namespace",
  "gkeNamespace": {
    "location": "us-central1-c",
    "clusterName": "cluster-1",
    "namespaceName": "test-kube-namespace"
  }
}

GKE service

Use the GkeService structure, for example:

{
  "displayName": "test-kube-service",
  "gkeService": {
    "location": "us-central1-c",
    "clusterName": "cluster-1",
    "namespaceName": "kube-system",
    "serviceName": "test-kube-service"
  }
}

GKE workload

Use the GkeWorkload structure, for example:

{
  "displayName": "frontend-a",
  "gkeWorkload": {
    "location": "us-central1-b",
    "clusterName": "cluster-2",
    "namespaceName": "default",
    "topLevelControllerType": "Deployment",
    "topLevelControllerName": "frontend-a"
  }
}

Cloud Run

Use the CloudRun structure, for example:

{
  "displayName": "test-cloudrun-service",
  "cloudRun": {
    "serviceName": "test-cloudrun-service",
    "location": "us-central1"
  }
}

For more information about managing services programmatically, see Working with the API.

Create a custom service

When no other service type meets your needs, create a custom service. With a custom service, you can arbitrarily group SLOs together in a way that is meaningful for your environment or create SLOs on business metrics that don't correspond to an existing microservice.

Use the Google Cloud console to create a custom service

To define a custom service by using the Google Cloud console, do the following:

  1. Click Define service on the Services Overview page to bring up the Define service pane.

  2. Select Custom Service.

    Use the **Custom Service** tab to define arbitrary services.

  3. Enter a display name for your custom service.

  4. Click Submit. When your service is created, a Success notice is displayed.

Use the API to create a custom service

To define a custom service by using the SLO API, post a Custom configuration object like the following to the services.create method:

{
  "displayName": "hello-world-service",
  "custom": {}
}

For more information about managing services programmatically, see Working with the API.

What's next

After you identify or create a new service, you can do the following:

  • Create an SLO for your new service. You must define at least one SLO for your new service for the service to be useful. For more information, see Creating an SLO.
  • Go to the dashboard for your new service. For a new service, the dashboard is empty, but you can define SLOs from the dashboard. For more information, see Using microservice dashboards.