2

I took a look very carefully to monitoring API. As far as I have read, it is possible to use gcloud for creating Monitoring Policies and edit the Policies ( Using Aleert API).

Nevertheless, from one hand it seems gcloud is able only to create and edit policies options not for reading the result from such policies. From this page I read this options:

Creating new policies
Deleting existing policies
Retrieving specific policies
Retrieving all policies
Modifying existing policies

On another hand I read from result of a failed request

Summary of the result of a failed request to write data to a time series.

So it rings a bell in my mind that I do can get a list of results like all failed request to write during some period. But how?

Please, my straigh question is: can I somehow either listen alert events or get a list of alert reults throw Monitoring API v3?.

I see tag_firestore_instance somehow related to firestore but how to use it and which information can I search for? I can't find anywhere how to use it. Maybe as common get (eg. Postman/curl) or from gcloud shell.

PS.: This question was originally posted in Google Group but I was encoraged to ask here.

*** Edited after Alex's suggestion

I have an Angular page listening a document from my Firestore database

export class AppComponent {
  public transfers: Observable<any[]>;

  transferCollectionRef: AngularFirestoreCollection<any>;

  constructor(public auth: AngularFireAuth, public db: AngularFirestore) {
    this.listenSingleTransferWithToken();
  }

  async listenSingleTransferWithToken() {
    await this.auth.signInWithCustomToken("eyJ ... CVg");
    this.transferCollectionRef = this.db.collection<any>('transfer', ref => ref.where("id", "==", "1"));
    this.transfers = this.transferCollectionRef.snapshotChanges().map(actions => {
      return actions.map(action => {
        const data = action.payload.doc.data();
        const id = action.payload.doc.id;
        return { id, ...data };
      });
    });
  }
}

So, I understand there is at least one reader count to return from

name: projects/firetestjimis
filter: metric.type = "firestore.googleapis.com/document/read_count"
interval.endTime: 2020-05-07T15:09:17Z

Try This API

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Jim C
  • 3,957
  • 25
  • 85
  • 162

1 Answers1

1

It was a little difficult to follow what you were saying, but here's what I've figured out.

This is a list of available Firestore metrics: https://cloud.google.com/monitoring/api/metrics_gcp#gcp-firestore

You can then pass these metric types to this API https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list

On that page, I used the "Try This API" tool on the right side and filled in the following

name = projects/MY-PROJECT-ID

filter = metric.type = "firestore.googleapis.com/api/request_count"

interval.endTime = 2020-05-05T15:01:23.045123456Z

In chrome's inspector, i can see that this is the GET request that the tool made: https://content-monitoring.googleapis.com/v3/projects/MY-PROJECT-ID/timeSeries?filter=metric.type%20%3D%20%22firestore.googleapis.com%2Fapi%2Frequest_count%22&interval.endTime=2020-05-05T15%3A01%3A23.045123456Z&key=API-KEY-GOES-HERE

EDIT: The above returned 200, but with an empty json payload. We also needed to add the following entry to get data to populate

interval.startTime = 2020-05-04T15:01:23.045123456Z

Also try going here console.cloud.google.com/monitoring/metrics-explorer and type firestore in the "Find resource type and metric" box and see if google's own dashboards has data populating. (This is to confirm that there is actually data there for you to fetch)

Alex
  • 5,141
  • 12
  • 26
  • Well, I am still struggling to get this work. I will edited my questions with pictures. In few words, following your suggestion, I tried these steps: (1) I read a document from my Firestore named firetestjimis (2) I tried get how many reads Firestore suffered until tomorrow and then the result is just {} – Jim C May 06 '20 at 20:13
  • 1
    unfortunately, i use datastore not firestore so I cant follow what you're doing exactly, but i tried it for datastore and also just got `{}`. But I was able to fix it by setting `interval.startTime` to `2020-05-04T15:01:23.045123456Z` – Alex May 06 '20 at 20:28
  • 2
    Another place you can try poking around is metrics explorer. Go here https://console.cloud.google.com/monitoring/metrics-explorer and type `firestore` in the `Find resource type and metric` box and see if google's own dashboards has data populating – Alex May 06 '20 at 20:30
  • Well, using Google's own dashboard is quite easy and intuitive. Unfrtunatelly I am facing a situation where Operators must look only at our internal Dashboards based on Dynatrace/Zabbix/ELK. On top of that, the only feature we will use from Google Cloud is Firestore. That is the reason I trying find someway to extrat/import/observe Firestore Metrics – Jim C May 06 '20 at 20:55
  • 1
    sure, i just meant that you should use 'metric explorer' to confirm that data is actually there. did setting `interval.startTime` fix anything? – Alex May 06 '20 at 21:06
  • You are right. By adding startTime it works although it doesn't inform as required. But it works on on Try It window. I guess I am close to make it work from curl. I added a new picture above. Do you know what are (1) [YOUR_API_KEY] and (2) [YOUR_ACCESS_TOKEN]? I guess [YOUR_ACCESS_TOKEN] can be the idToken I get from https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=AIzaSyDAd03oo5fPgV2l--oMWZ2Y23DCGihK3xs after posted my CustomToken. Regard API_Key I have not clue what it is about. If you know that I can give try with curl and probably my questions is answered – Jim C May 07 '20 at 13:30
  • I finally got it working. YOUR_API_KEY is the same I use for Angular FireBase SDK to log in Firestore. I copied it from "... firebaseConfig: { apiKey..." found in environment.ts. I know I have downloaded it few days ago. YOUR_ACCESS_TOKEN is neither my CustomToken nor IdToken validaded. I got it from gcloud auth application-default print-access-token. It is working now. Well, I still find quite dificult to navigate on Google Cloud documents and I still miss some kind of introdutory tutorials for someone desiring to extract info other than from dashboard. BTW, you answered my question – Jim C May 07 '20 at 13:52
  • 1
    Unfortunately, thats not an uncommon sentiment for GCP docs. They've been getting better over the years, but they can still leave a lot to be desired. I'm going to edit my answer to include `interval.startTime` – Alex May 07 '20 at 16:08