Monday, April 27, 2026
HomeCloud ComputingUninterested in looking out Slack, GitHub, and Google Drive individually? Do it...

Uninterested in looking out Slack, GitHub, and Google Drive individually? Do it all of sudden in SQL

[ad_1]

You realize the drill: The phrases you’re on the lookout for is likely to be in Slack, or GitHub, or Google Drive, or Google Sheets, or Zendesk, or … the record goes on. Looking out throughout these silos is a typical frustration. It needs to be frictionless, and this Steampipe dashboard makes it so.

This wasn’t my first rodeo. I began this journey in 1996 and have revisited the concept periodically. In 2018 I wrote a few model that was the basic instance of The Easiest Factor That Might Presumably Work: a net web page that corrals the search URLs for numerous companies and visits every in its personal tab. As foolish as that sounds it was useful sufficient to get used a bit, and never simply by me.

After all I wished to make use of the underlying APIs, normalize the outcomes, and merge them into a typical view. However the effort required to wrangle all of the APIs made that undertaking extra bother than it was value. In case you’ve carried out this sort of factor earlier than you understand that almost all companies present search APIs together with adapters to your most well-liked programming language. However every service may have its personal manner of calling the API, paginating outcomes, and formatting them. These variations create friction you might want to overcome so as to work with the leads to a constant manner.

When API wrangling turns into frictionless, although, many issues grow to be doable. Efficient metasearch is considered one of them. Steampipe will get you out of the enterprise of calling APIs, paginating outcomes, and unpacking JSON objects. It calls the APIs for you and streams the outcomes into database tables so you possibly can focus totally on working with the info. That solves the largest downside you face when constructing a metasearch dashboard.

Converging on a schema

The subsequent problem is to bind search outcomes to a typical schema. SQL is a superb surroundings by which to try this. The question that drives the dashboard proven within the screencast consists of three stanzas that you simply don’t must be a SQL wizard to jot down. All of them observe the identical sample as this one for looking out GitHub points.

choose
   'github_issue' as sort,
   repository_full_name || ' ' || title as supply,
   to_char(created_at, 'YYYY-MM-DD') as date,
   html_url as hyperlink,
   substring(physique from 1 for 200) || '...' as content material
from
   github_search_issue
the place
   $1 ~ 'github_issue'
   and question = 'in:physique in:feedback org:github ' || $2
   restrict $3

Objects in blue are the names of columns in a database desk—on this case github_search_issue, one of many tables made by Steampipe’s GitHub plugin. The Steampipe hub makes it simple to examine the names and descriptions of the columns within the desk, and exhibits you examples of use the data within the desk.

As a result of fetching the info doesn’t require calling APIs and unpacking JSON, you possibly can deal with higher-order search syntax, which is lots to consider, together with the attention-grabbing (and enjoyable!) problem of mapping supply columns to a typical schema.

Objects in crimson are the names of the columns that present up within the dashboard. For this dashboard we’ve determined every search outcome will map to those 5 columns: sort, supply, date, hyperlink, and content material. SQL’s AS clause makes it simple for every stanza to rename its columns to match the schema.

The complete question

Right here’s the complete question that drives the dashboard. There are three stanzas just like the one above, every written as a CTE (widespread desk expression) with parameters comparable to enter variables. And there’s virtually nothing else! Every stanza queries an API-based desk (slack_search, github_search_issue, googleworkspace_drive_my_file), selects (and possibly transforms) columns, then aliases the outcomes to match the schema. All that’s left is to UNION the three CTEs, which act like short-term tables, and order the outcomes.

with slack as (
  choose
    'slack' as sort,
    user_name || ' in #' || (channel ->> 'identify')::textual content as supply,
    to_char(timestamp, 'YYYY-MM-DD') as date,
    permalink as hyperlink,
    substring(textual content from 1 for 200) as content material
  from
    slack_search
  the place
    $1 ~ 'slack'
    and question = 'in:#steampipe after:${native.config.slack_date} ' || $2
  restrict $3
),
github_issue as (
  choose
    'github_issue' as sort,
    repository_full_name || ' ' || title as supply,
    to_char(created_at, 'YYYY-MM-DD') as date,
    html_url as hyperlink,
    substring(physique from 1 for 200) || '...' as content material
  from
    github_search_issue
  the place
    $1 ~ 'github_issue'
    and question = ' in:physique in:feedback org:${native.config.github_org} ' || $2
  restrict $3
),
gdrive as (
  choose
    'gdrive' as sort,
    exchange(mime_type,'utility/vnd.google-apps.','') as supply,
    to_char(created_time, 'YYYY-MM-DD') as date,
    'https://docs.google.com/doc/d/' || id as hyperlink,
    identify as content material
  from
    googleworkspace_drive_my_file
  the place
    $1 ~ 'gdrive'
    and question = 'fullText accommodates ' || '''' || $2 || ''''
  restrict $3
)

choose * from slack
union 
choose * from github_issue
union 
choose * from gdrive

order by
  date desc

Dashboards as code

Many dashboard methods can work with this question. You’ll be able to, for instance, join Metabase, or Tableau, or one other Postgres shopper to Steampipe and construct the identical form of interactive dashboard as proven right here. You’d do this work in a low-code surroundings the place widgets and settings are dealt with in a person interface. Steampipe’s dashboard subsystem takes a distinct strategy knowledgeable by its infrastructure-as-code (IaC) roots. Queries towards APIs needs to be expressed in SQL code that’s managed, like all different code, in version-controlled repositories. The dashboard widgets that show the outcomes of these queries ought to likewise be expressed in code, and on this case the language is Terraform’s HCL.

Right here’s the HCL definition of the metasearch dashboard. It declares three sorts of enter block: sources (multi-select), search_term (textual content), and max_per_source (single-select, which is the default). You are able to do way more with the enter block—notably, you possibly can fill it with outcomes from a SQL question, as proven in the documentation. That’s not wanted right here, although.

The desk block makes use of the question outlined above, and defines the parameters handed to it. The wrap argument ensures that columns with a number of textual content will probably be readable.

dashboard "metasearch" {

  enter "sources" {
    title = "sources"
    sort = "multiselect"
    width = 2
    possibility "slack" {} 
    possibility "github_issue" {}
    possibility "gdrive" {}
  }  

  enter "search_term" {
    sort = "textual content"
    width = 2
    title = "search time period"
  }

  enter "max_per_source" {
    title = "max per supply"
    width = 2
    possibility "2" {}
    possibility "5" {}
    possibility "10" {}   
    possibility "20" {}
  }  

  desk {
    title = "search slack + github + gdrive"
    question = question.metasearch
    args = [
      self.input.sources,
      self.input.search_term,
      self.input.max_per_source
    ]
    column "supply" {
      wrap = "all"
    }
    column "hyperlink" {
      wrap = "all"
    }
    column "content material" {
      wrap = "all"
    }
  }

}

Once more there’s not a lot else to see right here, nor ought to there be. Constructing dashboards as code shouldn’t require a number of advanced code, and it doesn’t.

No wizardry required

Simply as you don’t have to be a SQL wizard to create new subqueries, you additionally don’t have to be an HCL wizard so as to add them to the dashboard. Would you want so as to add sources? There are dozens of different plugins to select from, with extra added every month. They don’t all provide search however many do, and it’s simple to seek out them with (after all!) a Steampipe question.

choose
  identify
  html_url
from
  github_search_code
the place
  question = 'search org:turbot org:francois2metz org:ellisvalentiner org:theapsgroup'
  and identify ~ 'desk'
  and identify ~ 'search'
order by
  identify

Within the steampipe-samples repo we’ve included the code for the dashboard proven right here, together with an additional search stanza for Zendesk that we eliminated when our trial account expired. Have enjoyable extending this dashboard! If a search API you want isn’t already obtainable, drop by our Slack neighborhood and tell us. Someone would possibly already be writing the plugin you want—or possibly you’d prefer to sort out that your self. Each new plugin makes it doable for anybody who can work with fundamental HCL plus SQL to wield APIs like a professional and clear up actual issues.

Copyright © 2022 IDG Communications, Inc.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments