Test Snowplow Mini custom events

Hi,

I am running version 0.6.1 of Snow plow Mini and have tried the “Example Events” in the UI . Now I am looking to test adding some custom events of my own, but I am stuck on how to do that.

What I have done:
Completed step > Copy the Iglu rep to Snowplow Mini downloaded the schemas from the repo locally

What is the next step to test an event? Anything really works :smiley:

@Elena_Paraschiv, there are many ways to do so. Ideally, I would expect you to have an application with a Snowplow tracker embedded and use the methods of the tracker. If you do not have any yet (wonder why Snowplow Mini then), then you could use either an HTML link (GET request) with embedded data or curl (either GET or POST). Here’s an example of the curl command with both custom event and a custom entity/contexts attached to it sent via POST (endpoint /com.snowplowanalytics.snowplow/tp2):

curl --request POST \
  --url https://<SNOWPLOW_MINI_URI>/com.snowplowanalytics.snowplow/tp2 \
  --header 'content-type: application/json' \
  --data '{
  "schema": "iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4",
  "data": [
    {
      "e": "ue",
      "tv": "curl",
      "p": "srv",
      "aid": "test"
      "ue_pr": "{\"schema\":\"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0\",\"data\":{\"schema\":\"iglu:com.acme/event_name/jsonschema/1-0-0\",\"data\":{\"property_1\":<NUMERIC_VALUE>,\"property_2\":\"<STRING_VALUE>\"}}}",
      "co": "{\"schema\":\"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0\",\"data\":[{\"schema\":\"iglu:com.acme/entity_name/jsonschema/1-0-0\",\"data\":{\"property_1\":\"<STRING_VALUE>\"}}]}"
    }
  ]
}'

Note the event is composed according to Snowplow Tracker Protocol. It uses non-encoded data (hence, ue_pr, and co properties). I provided self-reference to some imaginary JSON schemas “com.acme/event_name/jsonschema/1-0-0” (for custom event) and “com.acme/entity_name/jsonschema/1-0-0” (for custom entity). To use GET requests, use /i endpoint. There are many more depending on the collector adaptor you want to send the data to.

If you want to use any of the JSON schemas hosted by Snowplow, you can refer to Iglu Central. Snowplow Mini automatically queries that repository.

Thank you for your reply @ihor.
Regarding your code snippet can I run it from my local terminal and what suffix extension should I use for it ? I tried curl_test.exe and curl_test.html, but didn’t work. I am sorry for the newbie question, not so familiar with server-side trying to learn it.

I found this javascript tracker for GTM in the docs which I am thinking to try next

Hi @Elena_Paraschiv
You would copy and paste the line @ihor gave you directly into the terminal (after making the edits to the URL) and it should execute immedatiely. The \ you see at the end of each line make this a multiline command.

If you want to save it as a file, then you can save it with the .sh extension, say curl_test.sh, and then in your terminal, navigate to the correct folder and type ./curl_test.sh.

If you get a permission denied: ./curl_test.sh error or similar then you need to make the script executable with chmod +x curl_test.sh.

Hope that helps!

Thanks Paul. Your indications help me to run the script. I don’t get a 200 response, just an ‘ok’ log, but unfortunately I can’t see the data in Kibana. Took a screenrecording of this https://www.loom.com/share/4090c7a81d8744a090d31f8e7c0ba729

Can you check if the event landing in the bad index? If there is an issue with the event payload, for instance if the payload failed validation, then the error should be in there.

Click where it says good and select bad:
Screenshot 2020-09-21 at 13.48.12

You are right @PaulBoocock . The issue was that the schema could not be found

I think the problem is that the com.acme schema is an imaginary one and not uploaded in the iglu-central/schemas folder.
So I am thinking for simplicity to modify my
curl_test.sh as
curl --request POST
–url http://34.91.20.131/com.snowplowanalytics.snowplow/tp2
–header ‘content-type: application/json’
–data ‘{
“schema”: “iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4”,
“data”: [
{
“e”: “ue”,
“tv”: “curl”,
“p”: “srv”,
“aid”: “test”,
“ue_pr”: “{"schema":"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0","data":{"schema":"iglu:com.acme/event_name/jsonschema/1-0-0","data":{"property_1":2,"property_2":"testa"}}}”
}
]
}’

and created this schema
com.acme/event_name/jsonschema > 1.0.0

{
	"$schema": "iglu:com.acme/event_name/jsonschema/1-0-0",
    "description": "Test schema",
    "self": {
        "vendor":"com.acme",
        "name": "test_schema",
        "format": "jsonschema",
        "version": "1-0-0"
    }
	"type": "object",
    "properties": {
        "property_1": {
            "type": "integer"
        },
        "property_2": {
            "type": "string"
        }
    },
    "required": ["property_1", "property_2"],
    "additionalProperties": false

}

and then upload the whole folder with the schema via terminal command : igluctl static push path/to-schema/ http://<Mini-domain-or-IP>/iglu-server <API key> --public as mentioned here . Do you think that makes sense ?

Yep, that makes sense! Good luck :slight_smile:

@Elena_Paraschiv, a word of caution. You have a mismatch in the self-reference and the actual event name.

"$schema": "iglu:com.acme/event_name/jsonschema/1-0-0",
                           // |---- event_name
"description": "Test schema",
"self": {
    "vendor":"com.acme",
    "name": "test_schema",   // <-- test_schema
    "format": "jsonschema",
    "version": "1-0-0"
}

That is if you name your event “test_schema” than the self-reference has to be "$schema": "iglu:com.acme/test_schema/jsonschema/1-0-0". Note the pattern “iglu:vendor/name/jsonschema/version”.

thanks @ihor, I modified that.
I have a bit of an issue how to upload the schema. I was trying through the

  1. igluctl command via ssh . I uploaded the file via buckets and then copied it. I couldn’t upload the whole folder , it didn’t allow the format “iglu:com.acme/test_schema/jsonschema/1-0-0”

  1. The other way was through swagger UI , but I am not sure what to add in the body key .

@Elena_Paraschiv, for a start I would like to warn you that Igluctl version to use depends on the version of Snowplow Mini you deployed. If you are using the latest versions of Snowplow Mini (0.9+) then you need to use the latest version of Igluctl as well, which could be downloaded from here, 0.7.1.

The path to the JSON schema is important, it is expected the JSON schema file to be located in schemas/<vendor>/<name>/jsonschema/. In you example, your (text, not shell) file 1-0-0 has to be located in schemas/com.acme/test_schema/jsonschema/ folder. Then if you are in the parent of schemas folder, you would upload the schema(s) to Snowplow Mini the way you did, that is

/path/to/igluctl static push ./schemas $SNOWPLOW_MINI_IP/iglu-server/ $SNOWPLOW_MINI_KEY

You also could use the full path to the schemas (./schema/schemas/com.acme/test_schema/jsonschema/1-0-0) if no other schemas are to be uploaded. The main point here the placement of the JSON schemas file in the correct folders.

If you are to upload the JSON schema via UI, the “body” field would contain the content of your JSON schema (the whole JSON).

2 Likes

I am almost there. Your replies have been so helpful @ihor and @PaulBoocock .
Managed to upload the schemas, but there is something wrong with it that I can’t figure out.
When I run lint on it this is what happens

@Elena_Paraschiv, actually it is my fault. The value of $schema has always to be "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#".

It is when you start tracking the custom event you would use

"schema": "iglu:com.acme/event_name/jsonschema/1-0-0,
"data": <JSON>
    curl --request POST \
      --url http://35.204.134.98/com.acme/tp2 \
      --header 'content-type: application/json' \
      --data '{
      "schema": "iglu:com.acme/test_schema/jsonschema/1-0-0",
      "data": [
        {
          "e": "ue",
          "tv": "curl",
          "p": "srv",
          "aid": "test",
          "ue_pr": "{\"schema\":\"iglu:com.acme/test_schema/jsonschema/1-0-0\",\"data\":{\"schema\":\"iglu:com.acme/test_schema/jsonschema/1-0-0\",\"data\":{\"property_1\":\"<STRING_VALUE>\"}}}"
        }
      ]
    }'

Thanks @ihor. The lint passed after i did that modifications. I tried to upload the POST request of the event accordingly, but my event goes into “bad flow”, with this error message

I tried changing to tp1 or simply removing tp from the adress, but it still returns an error

It’s this part I think:

--url http://35.204.134.98/com.acme/tp2

It should be http://34.91.20.131/com.snowplowanalytics.snowplow/tp2 - the com.snowplowanalytics.snowplow part doesn’t refer to the schema for your custom event, it refers to the ‘tracker protocol’ - which is the more generic format of the payload.

In case you didn’t know about them, the snowplow tracking CLI, or looking into one of our trackers might be of interest at this point, now that you seem to be up and running. Eg. I find a python script to be a lot less annoying than curl requests when I want a fast feedback loop for creating/testing custom events.

Nothing wrong with curl requests though, it’s personal preference. :slight_smile:

2 Likes